Android: DialogPreference color/style?

后端 未结 3 991
遇见更好的自我
遇见更好的自我 2021-01-11 13:24

My main preference activity is set to \"@android:style/Theme.Light\". One of my preferences is a DialogPreference who\'s Dialog contains a ListView. The ListV

相关标签:
3条回答
  • 2021-01-11 14:04

    I have a solution how you can do it programmatically (I think its the easier way):

    public class CustomDialogPreference extends DialogPreference {
    
    ...
    
    @Override
    protected void showDialog(Bundle state) {
        super.showDialog(state);
    
     //changing color of divider
        int divierId = getDialog().getContext().getResources()
                .getIdentifier("android:id/titleDivider", null, null);
        View divider = getDialog().findViewById(divierId);
        divider.setBackgroundColor(getContext().getResources().getColor(R.color.light_orange));
    
     //changing color of title textview
        int titleId = getDialog().getContext().getResources()
                .getIdentifier("android:id/alertTitle", null, null);
        TextView title = (TextView) getDialog().findViewById(titleId);
        title.setTextColor(getContext().getResources().getColor(R.color.light_orange));
    }
    
    ...
    
    }
    
    0 讨论(0)
  • 2021-01-11 14:08

    You can specify style of DialogPreference's dialog using android:alertDialogTheme (supported starting from API 11) them property of preferences activity:

    <style name="PreferencesActivityTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">        
        <item name="android:alertDialogTheme">@style/Theme.MyDialog</item>
    </style>
    
    <style name="Theme.MyDialog" parent="@style/Theme.AppCompat.Light.Dialog">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    
    0 讨论(0)
  • 2021-01-11 14:18

    You can inherit defult themes when creating styles in Android.

    Please read the documentation on Applying Styles and Themes specifically the section on inheritance

    You should be able to take Theme.light and correct any issues that you have with it.

    You may find that different vendors alter the themes on their devices so if you are targeting a broad range of hardware then you may be better creating a full theme to ensure that your app is consistent on all platforms.

    UPDATE

    As stated in this answer Consistent UI color in all Android devices there are public and non-public attributes. The answer provides a link to a list of public attributes however kernel.org is still down so you will need to dig through the source for core/res/res/values/public.xml

    0 讨论(0)
提交回复
热议问题