1,引用包
compile 'com.android.support:appcompat-v7:23.4.0'
2,调用V7包下的AlertDialog
new AlertDialog.Builder(MainActivity.this).setTitle("单选框").setSingleChoiceItems(
new String[]{"Item1", "Item2"}, 0,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setNegativeButton("取消", null).show();
出来的效果是这样的:
3,为在应用的主题添加以下代码
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!--自定义AlertDialog-->
<item name="alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert.Self</item>
</style>
<style name="Theme.AppCompat.Light.Dialog.Alert.Self"
parent="@style/Theme.AppCompat.Light.Dialog.Alert">
<!--修改AlertDialog按钮的颜色-->
<item name="colorAccent">#3F51B5</item>
</style>
参考:http://www.jianshu.com/p/fb671e11e455