Cannot lower case button text in android studio

2019-01-08 05:46发布

I have a trivial question that has been bothering me for a while. I tried to google this but no one seems to have the same problem as me or doesn't see it as an issue. When I make a button in activity_my.xml under layout

 <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_1_name"
    android:id="@+id/button2"
    android:layout_marginTop="140dp"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true" />

I get a button that looks like this][Imgur

even though my strings code is:

<resources>

<string name="app_name">HelloWorld</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="button_1_name">BuTtOn 1</string>

I know I am definitely missing something small here, but how do I get lower case/upper case working in the button text?

Thanks!

11条回答
ゆ 、 Hurt°
2楼-- · 2019-01-08 06:02

You could set like this

button.setAllCaps(false);

programmatically

查看更多
Summer. ? 凉城
3楼-- · 2019-01-08 06:06

in XML: android:textAllCaps="false"

Programmatically:

mbutton.setAllCaps(false);

查看更多
smile是对你的礼貌
4楼-- · 2019-01-08 06:09

there are 3 ways to do it.

1.Add the following line on style.xml to change entire application

<item name="android:textAllCaps">false</item>

2.Use

android:textAllCaps="false"

in your layout-v21

mButton.setTransformationMethod(null);
  1. add this line under the element(button or edit text) in xml

android:textAllCaps="false"

regards

查看更多
Bombasti
5楼-- · 2019-01-08 06:12

This is fixable in the application code by setting the button's TransformationMethod null, e.g.

mButton.setTransformationMethod(null);
查看更多
Fickle 薄情
6楼-- · 2019-01-08 06:14

There is a property in <Button> that is android:textAllCaps="false" that make characters in which you want in your own Small and caps. By Default its became True so write this code and make textAllCaps=false then you can write text on button in small and Caps letter as per your requirement. Complete code for a Button which allow use to write letters as per our requirement.

 <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btnLogin"
            android:text="Login for Chat"
            android:textAllCaps="false"/>
查看更多
兄弟一词,经得起流年.
7楼-- · 2019-01-08 06:14

I have faced this issue in TextView. I have tried

android:textAllCaps="false", 
mbutton.setAllCaps(false);   
<item name="android:textAllCaps">false</item> 

none of that worked for me. Finally I fed up and I have hard coded text, it is working.

tv.setText("Mytext");

tv is object of TextView. But as per coding standards, it is bad practice.

查看更多
登录 后发表回答