Title和Messge可以利用自定义TextView的方式更改样式
private void showAlertDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(MyDialogActivity.this,R.style.MyAlertButton);//传入样式修改按钮颜色
builder.setTitle("");
TextView textView = new TextView(this);
textView.setText("确定退出当前账号吗?");
textView.setTextSize(14);
textView.setTextColor(Color.parseColor("#999999"));
textView.setGravity(Gravity.CENTER_VERTICAL);
textView.setPadding(50,50,10,10);
//自定义textview的颜色
builder.setCustomTitle(textView);
builder.setCancelable(false);
builder.setPositiveButton("退出", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ActivityCollector.finishAll();
Intent intent = new Intent(MyDialogActivity.this,SignIn.class);
startActivity(intent);
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
builder.show();
}
Button可以通过获取AlertBuilder对象时传入样式来更改
<resources>
<style name="MyAlertButton"
//修改父样式的颜色
parent="@style/Theme.AppCompat.Light.Dialog.Alert">
<!--修改AlertDialog按钮的颜色-->
<item name="colorAccent">#FF0000</item>
</style>
</resources>