我有一个困扰我很久的小问题。我试图谷歌这个,但似乎没有人有同样的问题,我或不认为这是一个问题。当我在布局下的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>

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

谢谢!


当前回答

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

其他回答

这可以通过在activity_main.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" />

你也可以将它添加到你的styles/themes.xml中,为你的应用程序中的所有按钮更改它:

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

也可以通过在mainActivity中使用以下命令以编程方式设置。kt或mainActivity.java:

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

在按钮的.xml文件中添加这行——

android:textAllCaps="false"

你可以这样设定

button.setAllCaps(false);

以编程方式

<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"按钮 在这个问题上确实如此。