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.
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
}
-
Fork the following style xml code into your
<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>styles.xml
and modify their value as you want.<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>
-
Use
AlertDialogFastStyling
while buildingAlertDialog
component. The following samples are available for testing and their insets show the visual mappings to style items inAlertDialogFastStyling
.
AlertDialog dialog = new AlertDialog.Builder(context, R.style.AlertDialogFastStyling)
.setTitle("提醒")
.setPositiveButton("是", null)
.setNegativeButton("否", null)
.setMessage("检测到距离您上次清理已超过30天,是否立即清理?")
.show();
===
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();
===
AlertDialog dialog = new AlertDialog.Builder(context, R.style.AlertDialogFastStyling)
.setSingleChoiceItems(new String[] {"布丁味的老人茶", "奶昔", "巴拿拿牌烤香蕉"}, 0, null)
.setPositiveButton("确定", null)
.setNegativeButton("取消", null)
.show();
===
AlertDialog dialog = new AlertDialog.Builder(context, R.style.AlertDialogFastStyling)
.setMultiChoiceItems(new String[] {"布丁味的老人茶", "奶昔", "巴拿拿牌烤香蕉"},
new boolean[] {false, true, true},
null)
.setPositiveButton("确定", null)
.setNegativeButton("取消", null)
.show();
Copyright 2015 Cookizz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.