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);