AlertDialog中修改字体颜色。AlertDialog简单使用,小米2max无颜色

 
一、一般的dialog
(在有的Android 
AlertDialog dialog=new AlertDialog.Builder(mContext)不能构建成功
);

	需要先得到Builder对象:

AlertDialog.Builder build= new AlertDialog.Builder(mContext);
	build.setTitle("提示");
	build
.setMessage("您还未绑定支付宝?");


build
.setNegativeButton("考虑一下", null);

build
.setPositiveButton("前去绑定", null);

	
build
.show();

二、小米2max,确定和取消没有颜色的问题,或者设置Button的颜色?
	
AlertDialog.Builder build= new AlertDialog.Builder(mContext);
	build.setTitle("提示");
	build
.setMessage("您还未绑定支付宝?");
build
.setNegativeButton("考虑一下", null);

build
.setPositiveButton("前去绑定", null);
//build没有提供设置
NegativeButton和
PositiveButton的方法;但观察源码,
//发现dialog本身是有设置的方法.所以先得到dialog,再进行设置:
AlertDialog alertDialog = build.create();
	alertDialog.show();
	//左边的(积极的)设置为黑色
	alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(Color.BLACK);
	//右边的(消极的)设置为黑色
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.BLACK);

当然:还有其他的方法可以设置:
/**
 * Set a listener to be invoked when the negative button of the dialog is pressed.
 * @param textId The resource id of the text to display in the negative button
 * @param listener The {@link DialogInterface.OnClickListener} to use.
 *
 * @return This Builder object to allow for chaining of calls to set methods
 */

bulid.setNegativeButton(int textId,final OnClickListener listener);

另外: 
build.create();得到AlertDialog
源码:
/**
 * Creates an {@link AlertDialog} with the arguments supplied to this
 * builder and immediately displays the dialog.
 * <p>
 * Calling this method is functionally identical to:
 * <pre>
 *     AlertDialog dialog = builder.create();
 *     dialog.show();
 * </pre>
 */
public AlertDialog show() {
    final AlertDialog dialog = create();
    dialog.show();
    return dialog;
}

	AlertDialog 还可以通过继承来重写某些方法,实现new对象
	AlertDialog dialog=new AlertDialog.Builder(mContext);。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值