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