0

的标题字体颜色如何更改在以下优先XML的titlesummary的颜色:更改EditTextPreference

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

我在styles.xml试过这样:

<style name="SettingsTheme" parent="@style/AppBaseTheme"> 
    <item name="android:textColorPrimary">@color/green</item> 
    <item name="android:textColorSecondary">@color/red</item> 
    <item name="android:textColorTertiary">@color/blue</item> 
</style> 

textColorPrimary变化标题的颜色,但它也改变了我的工具栏中的文本颜色(我不想)。

textColorSecond虽然似乎正确地更改摘要的颜色。

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

回答

-1

我认为最简单的方法是继承EditTextPreference并调整onCreateView()onBindView()中的标题颜色。

public class MyEditTextPreference extends EditTextPreference { 

    // constructors omitted 

    @Override 
    protected void onBindView(View view) { 
     TextView titleView = (TextView) view.findViewById(android.R.id.title); 
     int color = getContext().getResources().getColor(R.color.preference_title); 
     titleView.setTextColor(color); 
    } 
} 

然后在你的喜好将XML你可以使用你的类,而不是(全名):

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

为什么这会降低投票率? – Karakuri

0

你需要明确定义为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默认样式之前的位置。

+0

我不认为用这种方法为标题设置文字颜色是可能的。 “EditTextPreference”及其任何父类都不寻找文本颜色属性。 – Karakuri