<style name="AlertDialog" parent="@style/Theme.AppCompat.Light.Dialog">
<!-- 这里设置背景为透明,为了隐藏边框 -->
<item name="android:windowBackground">@color/white</item>
<item name="android:windowNoTitle">true</item>
<!-- 这里是修改顶部标题背景颜色,具体颜色自己定,可以是图片 -->
<item name="android:topDark">@color/white</item>
<!-- 这里是修改内容区域背景颜色 -->
<item name="android:centerDark">@color/white</item>
<item name="android:windowIsTranslucent">true</item>
<item name="buttonBarPositiveButtonStyle">@style/positive</item>
<item name="buttonBarNegativeButtonStyle">@style/negative</item>
</style>
<style name="positive">
<item name="android:textColor">@color/colorAccent</item>
</style>
<style name="negative">
<item name="android:textColor">@color/colorAccent</item>
</style>
可以看到这里使用了style中的属性来修改Button的字体颜色:
buttonBarPositiveButtonStyle
buttonBarNegativeButtonStyle。
这里设置大小请注意:show()需要在setLayout()之前。
final AlertDialog.Builder builder = new AlertDialog.Builder(WebViewActivity.this, R.style.AlertDialog);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
double width = metrics.widthPixels * 0.9;
double height = metrics.heightPixels * 0.4;
AlertDialog alertDialog = builder.setMessage(message)
.setPositiveButton(R.string.sure, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
result.confirm();
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
result.cancel();
}
})
.create();
alertDialog.show();
alertDialog.getWindow().setLayout((int)width, ViewGroup.LayoutParams.WRAP_CONTENT);
http://blog.csdn.net/gs12software/article/details/48224885