在我的应用“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 谢谢


当前回答

下面是我在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>

其他回答

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

如果你使用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"。

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)

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

mButton。transformationMethod = null