Skip to content

Some visual parts of android.support.v7.AlertDialog can be fastly styled by inheriting its base theme instead of customizing new layouts, which is considered clumsy. Results of modifying those still agree with Material Design.

License

Notifications You must be signed in to change notification settings

Cookizz/AlertDialog-Fast-Styling-for-Android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AlertDialog-Fast-Styling

Some visual parts of android.support.v7.AlertDialog can be fastly styled by inheriting its base theme instead of customizing new layouts, which is considered clumsy. Modifying these visual parts still agrees with Material Design.

Requirement

  dependencies {
      compile 'com.android.support:appcompat-v7:22.2.0'
  }

Approach

  1. Fork the following style xml code into your styles.xml and modify their value as you want.

    <style name="AlertDialogFastStyling" parent="Theme.AppCompat.Light.Dialog.Alert"> @color/abc_primary_text_material_light @style/AlertDialogFastStyling.Title @drawable/abc_dialog_material_background_light 24dp 24dp @style/AlertDialogFastStyling.Button @drawable/abc_btn_radio_material @drawable/abc_btn_check_material </style>
     <style name="AlertDialogFastStyling.Title" parent="RtlOverlay.DialogWindowTitle.AppCompat">
         <item name="android:textAppearance">@style/AlertDialogFastStyling.Title.TextAppearance</item>
     </style>
     <style name="AlertDialogFastStyling.Title.TextAppearance">
         <item name="android:textSize">@dimen/abc_text_size_title_material</item>
         <item name="android:textColor">@color/abc_primary_text_material_light</item>
     </style>
     <style name="AlertDialogFastStyling.Button" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
         <item name="android:textColor">#009688</item>
         <item name="android:textSize">14sp</item>
     </style>
    
  2. Use AlertDialogFastStyling while building AlertDialog component. The following samples are available for testing and their insets show the visual mappings to style items in AlertDialogFastStyling.

Confirm Dialog
    AlertDialog dialog = new AlertDialog.Builder(context, R.style.AlertDialogFastStyling)
            .setTitle("提醒")
            .setPositiveButton("是", null)
            .setNegativeButton("否", null)
            .setMessage("检测到距离您上次清理已超过30天,是否立即清理?")
            .show();

confirm dialog

===

Choice Dialog
    AlertDialog dialog = new AlertDialog.Builder(context, R.style.AlertDialogFastStyling)
            .setItems(new String[] {"布丁味的老人茶", "奶昔", "巴拿拿牌烤香蕉"},
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
            })
            .show();

confirm dialog

===

Radio Dialog
    AlertDialog dialog = new AlertDialog.Builder(context, R.style.AlertDialogFastStyling)
            .setSingleChoiceItems(new String[] {"布丁味的老人茶", "奶昔", "巴拿拿牌烤香蕉"}, 0, null)
            .setPositiveButton("确定", null)
            .setNegativeButton("取消", null)
            .show();

confirm dialog

===

Check Dialog
    AlertDialog dialog = new AlertDialog.Builder(context, R.style.AlertDialogFastStyling)
            .setMultiChoiceItems(new String[] {"布丁味的老人茶", "奶昔", "巴拿拿牌烤香蕉"},
                    new boolean[] {false, true, true},
                    null)
            .setPositiveButton("确定", null)
            .setNegativeButton("取消", null)
            .show();

confirm dialog

About

Some visual parts of android.support.v7.AlertDialog can be fastly styled by inheriting its base theme instead of customizing new layouts, which is considered clumsy. Results of modifying those still agree with Material Design.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published