Styling titleDivider in Dialog

后端 未结 15 988
面向向阳花
面向向阳花 2020-12-06 05:27

I am wondering how it is possible to get rid of (or change color) titleDivider in Dialog. It is a blue line below dialog title shown on honeycomb+ devices.

15条回答
  •  抹茶落季
    2020-12-06 05:31

    You need to implement

    myDialog = builder.create();
    myDialog.setOnShowListener(new OnShowListenerMultiple());
    
    //----------------------------
    //Function to change the color of title and divider of AlertDialog
    public static class OnShowListenerMultiple implements DialogInterface.OnShowListener {
        @Override
        public void onShow( DialogInterface dialog ) {
            if( !(dialog instanceof Dialog) )
                return;
    
            Dialog d = ((Dialog) dialog);
            final Resources resources = d.getContext().getResources();
            final int color = AppUtility.getColor( resources, R.color.defaultColor );
    
            try {
                int titleId = resources.getIdentifier( "android:id/alertTitle", null, null );
                TextView titleView = d.findViewById( titleId );
                titleView.setTextColor( color );
            }
            catch( Exception e ) {
                Log.e( "XXXXXX", "alertTitle could not change color" );
            }
    
            try {
                int divierId = resources.getIdentifier( "android:id/titleDivider", null, null );
                View divider = d.findViewById( divierId );
                divider.setBackgroundColor( color );
            }
            catch( Exception e ) {
                Log.e( "XXXXXX", "titleDivider could not change color" );
            }
        }
    }
    

提交回复
热议问题