在我的应用“Tide Now WA”中,我最近测试了它的兼容性 新款Nexus 9平板电脑(Lollipop - API 21)。

它写一些按钮文本。这个应用程序使用Android 2.3和Android正确地编写文本 4.0. 即混合大写字母和小写字母。

当同一个应用程序在我的Nexus 9上运行时,所有的字母 正文均大写。

FWIW我的清单包含以下语句:

users -sdk android:minSdkVersion="10" android:targetSdkVersion="14"

我可以在我的代码中修复这个问题,还是操作系统中的一个bug 谢谢


我不知道为什么会发生这种情况,但有3个微不足道的尝试:

在layout-v21中使用android:textAllCaps="false" 以编程方式更改按钮的转换方法。mButton.setTransformationMethod(空); 检查全大写的样式

注意:公共无效setAllCaps(boolean allCaps), android:textAllCaps从API版本14可用。

棒棒糖默认带有“textAllCaps true”,所以你必须手动将其设置为false

OK, just ran into this. Buttons in Lollipop come out all uppercase AND the font resets to 'normal'. But in my case (Android 5.02) it was working in one layout correctly, but not another!? Changing APIs didn't work. Setting to all caps requires min API 14 and the font still resets to 'normal'. It's because the Android Material Styles forces a change to the styles if there isn't one defined (that's why it worked in one of my layout and not the other because I defined a style). So the easy fix is to define a style in the manifest for each activity which in my case was just: android:theme="@android:style/Theme.NoTitleBar.Fullscreen" (hope this helps someone, would have saved me a couple of hours last night)

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

mButton.setTransformationMethod(null);

如果你已经到达这里,因为你的facebook按钮文本出现在所有的大写,然后只需添加这个android:textAllCaps="false"在你的xml文件。这对我很管用。

将android: textAllCaps = " false "。如果你正在使用appcompat样式,确保textAllCaps在样式之前。否则样式将覆盖它。例如:

android:textAllCaps="false"
style="@style/Base.TextAppearance.AppCompat"

在Android Studio IDE中,你必须点击Filter图标来显示专家属性。然后您将看到textAllCaps属性。勾选,然后取消勾选。

有一个更简单的方法,适用于所有按钮,只是改变按钮的外观在你的主题,试试这个:

在values-21 / styles.xml

<resources>
    <style name="myBaseTheme"
        parent="@android:style/Theme.Material.Light">
        <item name="android:colorPrimary">@color/bg</item>
        <item name="android:colorPrimaryDark">@color/bg_p</item>
        <item name="android:textAppearanceButton">@style/textAppearanceButton</item>
    </style>

    <style name="textAppearanceButton" parent="@android:style/TextAppearance.Material.Widget.Button">
        <item name="android:textAllCaps">false</item>
    </style>
</resources>

PS:建议遵循材质设计的原则,你应该在Buttons中显示大写文本,http://www.google.com/design/spec/components/buttons.html

下面是我在values/themes.xml中所做的工作

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="buttonStyle">@style/MyButton</item>
    </style>

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

我不知道为什么@user1010160的答案是0。如果我有足够的声誉,我会给它+1。

由于我的应用程序是为小于14的API设计的,我不想在我的程序中添加代码,直到我读到他的答案,我才找到解决方案。他说的是,即使你已经做了什么是需要在应用程序样式它不会工作,除非你添加一个样式到你的活动,在那里你设置textAllCaps为假。

活动有一个样式是不够的(我的活动有一个样式),因为样式可能默认为AllCaps属性。你必须在activity中显式地设置,那个属性为false。

我现在在清单文件的应用程序和活动部分中都有它。

如果你使用appcompat-v7,你可以子类化AppCompatButtonand setSupportAllCaps(false),然后对你所有的按钮使用这个类。

/**
 * Light extension of {@link AppCompatButton} that overrides ALL CAPS transformation
 */
public class Button extends AppCompatButton {
    public Button(Context context, AttributeSet attrs) {
        super(context, attrs);
        setSupportAllCaps(false);
    }

    public Button(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setSupportAllCaps(false);
    }
}

请参阅AppCompatButton#setSupportAllCaps(boolean) Android文档。

在<Button>标签中添加android:textAllCaps="false"。

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

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

按样式添加这一行

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

使用android.support. widget。XML布局中的AppCompatButton将允许您避免使用layout-21或通过编程更改任何内容。当然,这也将与AppCompat v7库一起工作。

<android.support.v7.widget.AppCompatButton
    android:id="@+id/btnOpenMainDemo"
    android:textAllCaps="false"
    style="@style/HGButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/btn_main_demo"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"/>

希望这能有所帮助。

这个正在工作....只要在你的代码中在你的底部代码中添加这个:

android:textAllCaps="false"

它应该停用的大写字母,你试图键入小。

默认情况下,按钮在android提供所有大写关键字。如果你想按钮文本是小写或混合大小写,你可以禁用textAllCaps标志使用android:textAllCaps="false"

Java:

yourButton.setAllCaps(false);

科特林:

yourButton.isAllCaps = false

XML:

android:textAllCaps="false"

风格:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="buttonStyle">@style/yourButtonStyle</item>
    </style>

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

在布局:

   <Button
      .
      .
      style="@style/yourButtonStyle"
      .
      .
   />

另一个程序化的Kotlin替代品:

mButton。transformationMethod = null

使用这行android:textAllCaps="false"在你的xml

<Button
            android:id="@+id/btn_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/login_str"
            android:background="@color/colorBlue"
            android:textColor="@color/colorWhite"
            android:textAllCaps="false"
           />