Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改EditTextPreference的标题文本颜色_Android_Android Layout_Android Xml_Android Theme_Android Styles - Fatal编程技术网

Android 更改EditTextPreference的标题文本颜色

Android 更改EditTextPreference的标题文本颜色,android,android-layout,android-xml,android-theme,android-styles,Android,Android Layout,Android Xml,Android Theme,Android Styles,如何更改以下首选项XML中标题和摘要的颜色: <EditTextPreference android:key="username" android:title="Your Name" android:summary="Please provide your username." /> textColorPrimary会更改标题的颜色,但它也会更改我不想要的工具栏中文本的颜色 textColorSecond似乎正确地更改了摘要的颜色 如何在不影响工具栏文本颜色

如何更改以下首选项XML中标题和摘要的颜色:

<EditTextPreference
    android:key="username"
    android:title="Your Name"
    android:summary="Please provide your username." />
textColorPrimary会更改标题的颜色,但它也会更改我不想要的工具栏中文本的颜色

textColorSecond似乎正确地更改了摘要的颜色


如何在不影响工具栏文本颜色的情况下更改标题的颜色?

我认为最简单的方法是将EditTextPreference子类化,并在或中调整标题颜色

然后在您的首选项XML中,您将使用您的类而不是完全限定名:

<com.package.MyEditTextPreference
    android:key="username"
    android:title="Your Name"
    android:summary="Please provide your username." />

您需要明确定义EditTextPreference的样式,如下所示:

<style name="SettingsTheme" parent="@style/AppBaseTheme">
    <item name="android:editTextPreferenceStyle">@style/MyStyle</item>
</style>

<style name="MyStyle" parent="@android:style/Preference.DialogPreference.EditTextPreference">
    ...
</style>

然后,这将仅将您在MyStyle中定义的任何样式设置为EditTextPreference默认样式之前的位置。

我认为这样设置标题的文本颜色是不可能的。EditTextPreference及其任何父类都不会查找文本颜色属性。我得到错误:resource android:style/Preference.DialogPreference.EditTextPreference是私有的。
<com.package.MyEditTextPreference
    android:key="username"
    android:title="Your Name"
    android:summary="Please provide your username." />
<style name="SettingsTheme" parent="@style/AppBaseTheme">
    <item name="android:editTextPreferenceStyle">@style/MyStyle</item>
</style>

<style name="MyStyle" parent="@android:style/Preference.DialogPreference.EditTextPreference">
    ...
</style>