Today comes a question about button: The English string above the Android button will take its own initiative into uppercase, the Android 5.1 version number, for example, as seen:
Figure 1:button
Figure 2:textview
The definition code for this button is as follows
<button android:id= "@+id/addcontacts" android:layout_width= "match_parent" android:layout_height = "Wrap_content" android:text= "@string/contactlist_addcontact"/>
The definition code for TextView such as the following
<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 "/>
References the same string contactlist_addcontact. String contents such as the following:
<string name= "Contactlist_addcontact" >Add</string>
But the button shows that it is Add. And TextView shows that it is Add. I've never really met before. Depressed. And the other buttons are displayed as normal, as seen in the following:
The two button definition codes are as follows:
<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>
The string that is referenced is:
<string name= "Btn_cancel" >Cancel</string> <string name= "Btn_save" >Save</string>
All right. The above is the content of the problem. As to why this problem is, I expect that the Android 5.1 SDK has changed the default style of the button, and the style defaults to set the Textallcaps to true, and did not go into detail. Check the System Selection code: The No. 233 line of Frameworks/base/core/res/res/values/styles_material.xml, code such as the following:
<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>
Be able to find out that the textallcaps property is really set to true.
Here's how to solve the problem.
Just add a android:textallcaps= "false" property to the definition of the Add button, which is used to set whether to use uppercase letters to render the text.
Change the code to such as the following:
<button android:id= "@+id/addcontacts" android:layout_width= "match_parent" android:layout_height = "Wrap_content" android:textallcaps= "false" android:text= "@string/contactlist_addcontact"/>
All right, so it's over, and after the change, for example, the following:
====================================================================================
Ouyangpeng welcome reprint, sharing with people is the source of progress!
Reprint please keep the original address : Http://blog.csdn.net/ouyang_peng
====================================================================================
My Android Advanced tour------>android button above the English string of their own initiative to capitalize the problem solved