我有一个困扰我很久的小问题。我试图谷歌这个,但似乎没有人有同样的问题,我或不认为这是一个问题。当我在布局下的activity_my.xml中创建一个按钮时

 <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" />

我得到一个像这样的按钮

尽管我的字符串代码是:

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

我知道我在这里肯定错过了一些小东西,但我如何在按钮文本中得到小写/大写?

谢谢!


当前回答

XML代码格式 添加这一行android:textAllCaps="false" 像波纹码

 <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"
       ** android:textAllCaps="false" ** />

or

Java代码(以编程方式) 添加这一行到你的按钮setAllCaps(false)

Button btn = (Button) findViewById(R.id.button2);
btn.setAllCaps(false);

其他回答

我在TextView中遇到了这个问题。我试过了

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

这些对我都没用。最后我厌倦了,我有硬编码的文本,它是工作的。

tv.setText("Mytext");

tv是TextView的对象。但按照编码标准,这是一种糟糕的做法。

通过将按钮的TransformationMethod设置为空,这在应用程序代码中是可以修复的。

mButton.setTransformationMethod(null);

在XML: android: textAllCaps = " false "

编程:

mbutton.setAllCaps(假);

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:buttonStyle">@style/Button</item>
</style>

<style name="Button" parent="Widget.AppCompat.Button">
    <item name="android:textAllCaps">false</item>
</style>

在xml中添加android:textAllCaps="false"按钮 在这个问题上确实如此。