修改AlertDialog的宽高大小,Button的字体颜色等

    <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

https://stackoverflow.com/questions/4406804/how-to-control-the-width-and-height-of-the-default-alert-dialog-in-android





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值