टेक्स्टकॉलर विशेषता काम नहीं कर रही है। यहां मेरा एक्सएमएल है:एंड्रॉइड में वरीयता श्रेणी के टेक्स्ट रंग को कैसे बदला जाए?
<PreferenceCategory
android:title="Title"
android:textColor="#00FF00">
कोई विचार?
टेक्स्टकॉलर विशेषता काम नहीं कर रही है। यहां मेरा एक्सएमएल है:एंड्रॉइड में वरीयता श्रेणी के टेक्स्ट रंग को कैसे बदला जाए?
<PreferenceCategory
android:title="Title"
android:textColor="#00FF00">
कोई विचार?
उपयोग इस अनुकूलित PreferenceCategory वर्ग:
public class MyPreferenceCategory extends PreferenceCategory {
public MyPreferenceCategory(Context context) {
super(context);
}
public MyPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyPreferenceCategory(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
TextView titleView = (TextView) view.findViewById(android.R.id.title);
titleView.setTextColor(Color.RED);
}
}
और अपने Pref.xml फ़ाइल में जोड़ें:
<ali.UI.Customize.MyPreferenceCategory android:title="@string/pref_server" />
एक समाधान अपने PreferenceScreen के लिए एक थीम बनाना है। अपने AndroidManifest.xml में
<style name="PreferenceScreen" parent="YourApplicationThemeOrNone">
<item name="android:textColor">@color/yourCategoryTitleColor</item>
</style>
तो: तो अपने themes.xml या styles.xml में (बेहतर यह themes.xml में डालने के लिए)
<activity
android:name="MyPreferenceActivity"
...
android:theme="@style/PreferenceScreen" >
</activity>
यह मेरे लिए पूरी तरह से काम किया।
मेरे लिए, यह सही जवाब है – Javi
public class MyPreferenceCategory extends PreferenceCategory {
public MyPreferenceCategory(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyPreferenceCategory(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
protected View onCreateView(ViewGroup parent) {
// It's just a TextView!
TextView categoryTitle = (TextView)super.onCreateView(parent);
categoryTitle.setTextColor(parent.getResources().getColor(R.color.orange));
return categoryTitle;
}
}
और अपने prefs.xml में:
<com.your.packagename.MyPreferenceCategory android:title="General">
.
.
.
</com.your.packagename.MyPreferenceCategory>
या आप भी इस answer
यह एक संशोधन के साथ मेरे लिए पूरी तरह से काम किया। बजाय 'categoryTitle.setTextColor (parent.getResources() getColor (R.color.orange)।);' मैं का इस्तेमाल किया था 'categoryTitle.setTextColor (Color.BLACK);' – ckn
यह करने के लिए एक आसान तरीका है का उपयोग कर सकते यहाँ preferenceCategory के लिए कस्टम लेआउट सेट करने के लिए है:
<PreferenceCategory
android:layout="@layout/preferences_category"
android:title="Privacy" >
फिर अपना कोड अपनी प्राथमिकताओं_category लेआउट फ़ाइल के अंदर सेट करें:
<TextView
android:id="@android:id/title"
android:textColor="@color/deep_orange_500"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textAllCaps="true"/>
अन्य तरह से चारों ओर हो जाएगा अपने AppTheme में विषय का उल्लेख है, अनुप्रयोग स्तर
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
.....//your other items
<item name="preferenceTheme">@style/PrefTheme</item>
</style>
<style name="PrefTheme" parent="@style/PreferenceThemeOverlay">
<item name="preferenceCategoryStyle">@style/CategoryStyle</item>
</style>
<style name="CategoryStyle" parent="Preference.Category">
<item name="android:layout">@layout/pref_category_view</item>
</style>
एक्सएमएल: pref_category_view
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@android:id/title"
style="?android:attr/listSeparatorTextViewStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:textColor="@color/red"
android:layout_height="wrap_content"
/>
अधिक अनुकूलन यात्रा v7 Preferences res
महत्वपूर्ण के लिए: मैं lib v7 Preference से PreferenceFragmentCompat उपयोग कर रहा हूँ।
हैप्पी_Coding;
वरीयता श्रेणी के टेक्स्ट रंग को बदलने के लिए केवल अपने एंड्रॉइड मैनिफेस्ट में अपने PreferenceActivity
पर एक थीम सेट करें और सुनिश्चित करें कि colorAccent आइटम मौजूद है। यह रंग आपके PreferenceCategory
द्वारा लिया जाता है।
यह सही जवाब है!
वास्तव में यह पता चला कि colorAccent
का उपयोग कर वरीयता श्रेणी पाठ।
यदि आपके ऐप ने colorAccent
की शैली का उपयोग नहीं किया है, तो आप styles.xml
पर जा सकते हैं और <item name="colorAccent">@color/colorPrimary</item>
ढूंढ सकते हैं, और जितना चाहें रंग बदल सकते हैं।
आईएमओ, यह लॉलीपॉप और सामग्री डिजाइन के रूप में सही जवाब है। संदर्भ - http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/frameworks/base/core/res/res/layout/preference_category_material.xml? av = च – Ginandi
मैंने पाया कि 'findViewById()' अभी भी 'bindView() 'में काम नहीं किया है। मैंने इसे 'क्रिएटिव व्यू()' में किया, जिसने काम किया। – ryan
'titleView.setTextColor (Color.RED);' 'NullPointerException 'फेंकता है। कोई फिक्स? –
फिक्स पहली टिप्पणी में ही है ... – Rohan