我的Android进阶之旅------>android Button上面的英文字符串自己主动大写的问题解决
今天碰到一个关于Button的问题:android Button上面的英文字符串会自己主动变成大写,执行的Android 5.1版本号,例如以下图所看到的:
图1:Button
图2:TextView
这个Button的定义代码例如以下
<Button android:id="@+id/addContacts" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/contactList_addContact" />TextView的定义代码例如以下
<TextView android:layout_width="match_parent" android:layout_height="0dp" android:layout_margin="10dp" android:layout_weight="1" android:gravity="center" android:text="@string/contactList_addContact" android:textSize="24sp" />
引用同一个字符串contactList_addContact。字符串内容例如以下:
<string name="contactList_addContact">Add</string>
可是Button显示出来就是ADD。而TextView显示出来就是Add。之前还真的没遇到过。郁闷。并且其它的Button都是显示正常,例如以下所看到的:
这两个按钮定义代码例如以下:
<LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:layout_margin="10dp" android:layout_weight="1" android:gravity="center" android:orientation="horizontal" > <Button android:id="@+id/btn_cancel" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:gravity="center" android:text="@string/btn_cancel" android:textColor="@color/black" /> <Button android:id="@+id/btn_save" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:gravity="center" android:text="@string/btn_save" android:textColor="@color/black" /> </LinearLayout>
所引用的字符串为:
<string name="btn_cancel">Cancel</string> <string name="btn_save">Save</string>
好吧。以上就是问题的内容。至于为什么会有这个问题我预计是Android 5.1的SDK把Button的默认Style改了,样式默认把textAllCaps设置为true了,也没有去细致研究。查看系统选代码:frameworks/base/core/res/res/values/styles_material.xml的第233行,代码例如以下:
<style name="TextAppearance.Material.Button">
<item name="textSize">@dimen/text_size_button_material</item>
<item name="fontFamily">@string/font_family_button_material</item>
<item name="textAllCaps">true</item>
<item name="textColor">?
attr/textColorPrimary</item>
</style>
能够发现真的是把textAllCaps属性设置为true了。
以下来说说怎么解决问题。
仅仅须要在Add按钮的定义中加上一个 android:textAllCaps="false"属性就可以,该属性是用来设置是否使用大写字母来呈现文本。
即把代码改成例如以下:
<Button android:id="@+id/addContacts" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAllCaps="false" android:text="@string/contactList_addContact" />
好吧,这样就攻克了,改完后的效果图例如以下:
====================================================================================
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
====================================================================================
- 我的Android进阶之旅------>android Button上面的英文字符串自动大写的问题解决
- 我的Android进阶之旅------>Android字符串资源中的单引號问题error: Apostrophe not preceded by 的解决的方法
- android Button上面的英文字符串自动大写的问题解决
- 我的Android进阶之旅------>Android字符串资源中的单引号问题error: Apostrophe not preceded by 的解决办法
- 我的Android进阶之旅------>Android中ListView中嵌套(ListView)控件时item的点击事件不起作的问题解决方法
- Android:解决“按钮 Button设置文字String 含字母时 字母默认自动转为大写字符串” 问题
- Android 自己主动化測试(3)<monkeyrunner> 依据ID查找对象&touch&type (python)
- 解决 Button 和 TabLayout 英文自动大写的问题
- Android SDK Manager更新<dl-ssl.google.com> != <www.google.com> 问题解决方法
- Android解决图片资源比较大的问题--->.9图片的制作和使用
- 扫描枪在Android 系统上面扫描的时候缺少一位,<已解决>百度输入法的问题
- 我的Android进阶之旅------>解决 Error: ShouldNotReachHere() 问题
- 我的Android进阶之旅------>Android无第三方Jar包的源代报错:The current class path entry belongs to container ...的解决方法
- 解决Android Button 字母自动全部大写的问题
- Android Studio Button英文字符自动变成大写的问题
- 我的Android进阶之旅------>Android中ListView中嵌套(ListView)控件时item的点击事件不起作的问题解决方法
- [Android] Android Studio 解决Button按钮文字全大写的问题
- 我的Android进阶之旅------>Android使用cmd窗口进行adb logcat时出现中文乱码问题的解决办法
- Android问题解决之使用字符串&对象空值判断
- 关于android导入工程时出现的@Override错误问题的解决<转>