您的位置:首页 > 其它

Button英文字符自动大写的问题

2016-05-31 00:56 344 查看

问题

如题

原因分析

以我项目中使用Theme.AppCompat.Light.DarkActionBar主题为例。跟踪源码可发现,该主题中有:

<style name="Base.TextAppearance.AppCompat.Button">
<item name="android:textSize">@dimen/abc_text_size_button_material</item>
<item name="textAllCaps">true</item>
<item name="android:textColor">?android:textColorPrimary</item>
</style>


关键的原因在于:

<item name="textAllCaps">true</item>


当然,如果细看的话,会发现不止是Button这一控件的该属性被设置成了true。

解决方法

由上面的原因分析便可简单的找到解决方法,这里简单提及两种方式:

修改style.xml如:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<item name="textAllCaps">false</item>
</style>


将textAllCaps属性设置为false。如此,整个项目中的相关控件的(字符)文本都可避免被自动转换为大写。

2. 在具体控件中重置该属性为false,如:

<Button
android:id="@+id/btn_answer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="false"
/>


这方法唯一不足的是需要对每个相关控件都设置该属性。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: