References To Theme Attributes के माध्यम से पढ़ने के बाद मैं अपने कस्टम थीम में एक विशेषता के मान को संदर्भित करने का प्रयास कर रहा हूं।संदर्भित शैली विशेषताओं को ओवरराइड करना
मैं एक CheckedTextView
<CheckedTextView
android:id="@+id/contactInfo"
style="@style/ListViewCheckedTextViewRowStyle" >
</CheckedTextView>
उपयोगकर्ता परिभाषित शैली के लिए एक उपयोगकर्ता परिभाषित शैली लागू कर रहा हूँ के रूप में परिभाषित किया गया है:
<style name="ListViewCheckedTextViewRowStyle" parent="@style/ListViewRowStyle">
<item name="android:checkMark">?android:listChoiceIndicatorMultiple</item>
</style>
मेरे द्वारा बनाए गए मेरे विषय के रूप में परिभाषित किया गया है:
<style name="Theme.Yellowgreen" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:listChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>
</style>
हालांकि, चेकमार्क स्टाइल जो प्रदर्शित हो जाता है वह डिवाइस का डिफ़ॉल्ट थीम का ड्रॉब है ले और मेरे उपयोगकर्ता को आकर्षित करने योग्य नहीं है।
एक ही रास्ता मैं अपने drawable प्रदर्शित किया जा सकता है के साथ है:
<style name="ListViewCheckedTextViewRowStyle" parent="@style/ListViewRowStyle">
<item name="android:checkMark">@drawable/btn_check_holo_light</item>
</style>
लेकिन वह इस विशेषता अधिभावी, खासकर जब से मैं कई विषयों में इस विशेषता को ओवरराइड करना चाहेंगे का पूरा उद्देश्य धरा।
मैं इस तरह मेरी Activity
की onCreate()
विधि में विषय की स्थापना कर रहा हूँ:
<application android:theme="@style/Theme.Yellowgreen" >
लेकिन उस:
public void onCreate(Bundle savedInstanceState) {
this.setTheme(R.style.Theme_Yellowgreen);
super.onCreate(savedInstanceState);
// ...
}
मैं भी AndroidManifest.xml में विषय स्थापित करने के लिए की तरह दाखिल करने की कोशिश की काम नहीं किया क्या गलत हो सकता है?
अद्यतन
मैं सिर्फ एक छोटा सा नमूना प्रोजेक्ट बनाया है और यह कोड मैं पोस्ट के ऊपर काम कर रहा है की तरह लग रहा है। इसलिए मेरे पास कुछ अन्य शैलियों होनी चाहिए जो इस संपत्ति को ओवरराइड कर रहे हैं या शायद इसे मेरे लेआउट एक्सएमएल फाइलों के साथ करना है।
मेरी बड़ी परियोजना में, मेरे पास Activity
के भीतर दो Fragments
हैं। Fragments
दोनों Listviews
Adapters
द्वारा समर्थित हैं।
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.contact_entry, null);
}
//...
return convertView;
}
Fragment B
में Adapter
की getView()
विधि इस प्रकार है:: इस प्रकार
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, parent, false);
}
//...
return convertView;
}
लेआउट परिभाषित कर रहे हैं: Fragment A
में Adapter
की getView()
विधि इस प्रकार है
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/list_item_header" />
<include layout="@layout/contact_entry" />
<View android:id="@+id/list_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:drawable/divider_horizontal_dark" />
</LinearLayout>
list_item_header.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header_text"
android:layout_width="match_parent"
android:layout_height="25dip"
android:background="@color/dark_blue"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold" />
contact_entry।एक्सएमएल
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contactEntry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal" >
<QuickContactBadge
android:id="@+id/contactPic"
style="@style/ContactPicStyle" />
<CheckedTextView
android:id="@+id/contactInfo"
style="@style/ListViewCheckedTextViewRowStyle" >
</CheckedTextView>
</LinearLayout>
किसी कारण से, Fragment B
में थीम पर आधारित सही का निशान विशेषता Fragment A
में जबकि सही ढंग से प्रस्तुत नहीं हो रही, सही का निशान वर्तमान YellowGreen विषय का उपयोग करता है और सही ढंग से स्टाइल है। यह क्यों हो रहा है?
क्या आपने अपना _YellowGreen_ थीम मैनिफेस्ट में निर्दिष्ट किया है? – dominus
मैंने अभी अपनी स्टाइल फाइलों का परीक्षण करने के लिए एक नमूना प्रोजेक्ट बनाया है और सबकुछ मेरे लिए ठीक काम करता है। तो मैं दूसरा _dominus'_ प्रश्न: क्या आपने मैनिफेस्ट में 'येलोग्रीन' पर गतिविधि विषय सेट किया है? – Idolon
हे @dominus और @Idolon, मैंने सवाल अपडेट किया। मैंने गतिविधि विषय को दो अलग-अलग तरीकों से सेट करने का प्रयास किया लेकिन 'android: listChoiceIndicatorMultiple' शैली विशेषता को ओवरराइड करने में असफल रहा। – toobsco42