不能在android studio中小写按钮文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24880388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:53:40  来源:igfitidea点击:

Cannot lower case button text in android studio

androidbuttonandroid-studio

提问by Alex H

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

我有一个琐碎的问题困扰了我一段时间。我试图用谷歌搜索这个,但似乎没有人和我有同样的问题,或者不认为这是一个问题。当我在布局下的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" />

I get a button that looks like this][Imgur

我得到一个看起来像的按钮 这个][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!

谢谢!

回答by Stelian Matei

You could add android:textAllCaps="false"to the button.

您可以添加android:textAllCaps="false"到按钮。

The button text might be transformed to uppercase by your app's theme that applies to all buttons. Check themes / styles files for setting the attribute android:textAllCaps.

按钮文本可能会被应用到所有按钮的应用主题转换为大写。检查主题/样式文件以设置属性android:textAllCaps

回答by susemi99

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

回答by Attaullah

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

这可以在应用程序代码中通过将按钮的 TransformationMethod 设置为 null 来修复,例如

mButton.setTransformationMethod(null);

回答by Hai Rom

add android:textAllCaps="false"in xml button It's true with this issue.

add android:textAllCaps="false"in xml button 这个问题是对的。

回答by Dinithe Pieris

there are 3 ways to do it.

有3种方法可以做到。

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

1. 在 style.xml 上添加以下行以更改整个应用程序

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

2.Use

2.使用

android:textAllCaps="false"

in your layout-v21

在你的 layout-v21

mButton.setTransformationMethod(null);
  1. add this line under the element(button or edit text) in xml
  1. 在 xml 中的元素(按钮或编辑文本)下添加这一行

android:textAllCaps="false"

机器人:textAllCaps =“假”

regards

问候

回答by PAWAN LAKHOTIA

In your .xml file within Button add this line--

在 Button 内的 .xml 文件中添加这一行——

android:textAllCaps="false"

回答by missionMan

You could set like this

你可以这样设置

button.setAllCaps(false);

programmatically

以编程方式

回答by Thirumalvalavan

I have faced this issue in TextView. I have tried

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

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.

tv 是 TextView 的对象。但根据编码标准,这是不好的做法。

回答by Vasinda

in XML Code
add this line android:textAllCaps="false"like bellow code

在 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

或者

in Java code (programmatically)
add this line to your button setAllCaps(false)

在 Java 代码中(以编程方式
将此行添加到您的按钮setAllCaps(false)

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

回答by Pradeep Sheoran

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 Trueso write this code and make textAllCaps=falsethen 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.

android:textAllCaps="false"中有一个属性,<Button>可以在您自己的小型和大写字母中生成您想要的字符。默认情况下它变成了True所以写这个代码并使textAllCaps=false然后你可以根据你的要求在按钮上用小写字母和大写字母写文本。按钮的完整代码,允许根据我们的要求编写字母。

 <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btnLogin"
            android:text="Login for Chat"
            android:textAllCaps="false"/>