android自定义style右对齐,android – 在AlertDialog中右对齐文本

据我所知,从AlertDialog和AlertController的代码中,您无法访问负责消息和标题的TextView.

您可以使用反射在AlertDialog实例中到达mAlert字段,然后再次使用反射来访问mAlert的mMessage和mTitle字段.虽然我不推荐这种方法,因为它依赖于内部(可能在将来发生变化).

作为另一个(可能更好)的解决方案,您可以通过AlertDialog构造函数应用自定义主题.这将允许您右对齐该对话框中的所有TextView.

protected AlertDialog (Context context, int theme)

这应该是更容易和更强大的方法.

这是一步一步的说明:

步骤1.创建res / values / styles.xml文件.其内容如下:

right|center_vertical

right|center_vertical

@style/RightJustifyTextView

@style/RightJustifyDialogWindowTitle

步骤2.创建RightJustifyAlertDialog.java文件.其内容如下:

public class RightJustifyAlertDialog extends AlertDialog

{

public RightJustifyAlertDialog(Context ctx)

{

super(ctx, R.style.RightJustifyTheme);

}

}

第3步.使用RightJustifyAlertDialog对话框:

AlertDialog dialog = new RightJustifyAlertDialog(this);

dialog.setButton("button", new OnClickListener()

{

public void onClick(DialogInterface arg0, int arg1)

{

}

});

dialog.setTitle("Some Title");

dialog.setMessage("Some message");

dialog.show();

第4步.检查结果:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值