Mic*_*ith 30 android android-preferences
textColor属性不起作用.这是我的XML:
<PreferenceCategory
android:title="Title"
android:textColor="#00FF00">
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
Ali*_*iSh 53
使用此自定义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);
}
}
Run Code Online (Sandbox Code Playgroud)
并在Pref.xml文件中添加:
<ali.UI.Customize.MyPreferenceCategory android:title="@string/pref_server" />
Run Code Online (Sandbox Code Playgroud)
fla*_*yte 35
一种解决方案是为PreferenceScreen制作主题.所以在你的themes.xml或styles.xml中(最好把它放在themes.xml中):
<style name="PreferenceScreen" parent="YourApplicationThemeOrNone">
<item name="android:textColor">@color/yourCategoryTitleColor</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后在你的AndroidManifest.xml中:
<activity
android:name="MyPreferenceActivity"
...
android:theme="@style/PreferenceScreen" >
</activity>
Run Code Online (Sandbox Code Playgroud)
它对我来说很完美.
Sim*_*mon 31
一种简单的方法是在这里设置preferenceCategory的自定义布局:
<PreferenceCategory
android:layout="@layout/preferences_category"
android:title="Privacy" >
Run Code Online (Sandbox Code Playgroud)
然后在preferences_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"/>
Run Code Online (Sandbox Code Playgroud)
小智 11
要更改首选项类别的文本颜色,只需PreferenceActivity在Android Manifest中为您设置主题,并确保colorAccent项目存在.这种颜色是由你的PreferenceCategory.
小智 9
实际上刚刚发现使用colorAccent.
如果您的应用程序没有使用 样式colorAccent,您可以去styles.xml查找<item name="colorAccent">@color/colorPrimary</item>,并根据需要更改颜色。
其他方式将在您的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>
Run Code Online (Sandbox Code Playgroud)
XML : 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"
/>
Run Code Online (Sandbox Code Playgroud)
如需更多定制,请访问v7 Preferences res
重要提示:我使用PreferenceFragmentCompat从LIB V7偏好。
使用 Material Theme,您只需覆盖以下属性:
<style name="YourTheme" parent="@style/Theme.MaterialComponents">
<item name="colorAccent">@color/your_custom_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34378 次 |
| 最近记录: |