Android: DialogPreference color/style?

后端 未结 3 993
遇见更好的自我
遇见更好的自我 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));
    }
    
    ...
    
    }
    

提交回复
热议问题