Android AlertDialog -AppCompatV7更改默认按钮大写的设定

在Android AppCompatV7中,系统默认将AlertDialog按钮文本设为全大写。常规方法通过修改style.xml的buttonBarButtonStyle不起作用。解决方法包括自定义属性MyCustomTabTextAppearance,然后在AlterDialog中应用,并使用该自定义属性来避免按钮文本全大写问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android AlertDialog -AppCompatV7更改默认按钮大写的设定

系统升级之后的控件总是把英文默认成全部大写,例如Button 按钮和AlertDialog的按钮文字。网上有很多方法都是在style.xml 里面继承buttonBarButtonStyle 父类 然后将textAllCaps设置为false 但是不知道为什么在APPCompatibleV7 这样写是没有效果的。


解决方法

  • 1.自定义属性
    style.xml自定义属性MyCustomTabTextAppearance
<style name="MyCustomTabTextAppearance" parent="TextAppearance.AppCompat">
        <item name="textAllCaps">false</item>
 </style

  • 2.AlterDialog自定义
 AlertDialog dialog=new AlertDialog.Builder(this)
                    .setTitle("Title")
                    .setMessage(getString("Content")
                    .setPositiveButton("Yes",null)
                    .setNegativeButton("No",null)
                    .show();
  • 3.使用自定义属性
//获取按钮
Button mNegativeButton = dialog.getButton(AlertDialog.BUTTON_NEGATIVE) ;
            Button mPOstiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE) ;
//按钮使用自定属性 这样按钮的英文字体不会再是默认大写
mPOstiveButton.setTextAppearance(this,R.style.MyCustomTabTextAppearance);
            mNegativeButton.setTextAppearance(this,R.style.MyCustomTabTextAppearance);

代码

 AlertDialog dialog=new AlertDialog.Builder(this)
                    .setTitle("Title")
                    .setMessage(getString("Content")
                    .setPositiveButton("Yes",null)
                    .setNegativeButton("No",null)
                    .show();
        Button mNegativeButton = dialog.getButton(AlertDialog.BUTTON_NEGATIVE) ;
        Button mPOstiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE) ;

        mPOstiveButton.setTextAppearance(this,R.style.MyCustomTabTextAppearance);
        mNegativeButton.setTextAppearance(this,R.style.MyCustomTabTextAppearance);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值