为什么我的Button文本强制在Lollipop上的所有大写?

问题描述 投票:379回答:16

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

它会写一些按钮文字。此应用程序使用Android 2.3和Android 4.0正确编写文本。即混合资本和小写字母。

当我的Nexus 9上运行相同的应用程序时,文本中的所有字母都大写。

FWIW我的清单包含以下声明:

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

我可以在我的代码中解决这个问题,还是在O.S.中的一个错误。谢谢

android android-5.0-lollipop android-button android-styles
16个回答
570
投票

我不知道它为什么会发生,但有三个微不足道的尝试:

  1. 在你的android:textAllCaps="false"中使用layout-v21
  2. 以编程方式更改按钮的转换方法。 mButton.setTransformationMethod(null);
  3. 检查你的风格Allcaps

注意:public void setAllCaps (boolean allCaps) android:textAllCaps可从API版本14获得。


10
投票

在XML布局中使用android.support.v7.widget.AppCompatButton可以避免必须使用layout-21或以编程方式更改任何内容。当然,这也适用于AppCompat v7库。

http://www.google.com/design/spec/components/buttons.html

希望这可以帮助。


8
投票

在Android Studio IDE中,您必须单击“过滤器”图标以显示专家属性。然后你会看到<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"/> 财产。检查一下,然后取消选中它。


8
投票

您可以将textAllCaps添加到按钮。

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


2
投票

好的,刚碰到这个。棒棒糖中的按钮全部大写,字体重置为“正常”。但在我的情况下(Android 5.02)它正确地在一个布局中工作,但不是另一个!? 更改API不起作用。 设置为全部大写需要最小API 14,字体仍然重置为“正常”。 这是因为如果没有一个定义的话,Android材质样式强制改变样式(这就是为什么它在我的一个布局中工作而不是另一个因为我定义了一个样式)。 因此,简单的解决方法是在清单中为每个活动定义一个样式,在我的例子中只是: 机器人:主题= “@安卓风格/ Theme.NoTitleBar.Fullscreen” (希望这有助于某人,昨晚能节省我几个小时)


2
投票

如果你到这里是因为你的facebook按钮文本出现在所有大写字母中,那么只需在你的xml文件中添加这个android:textAllCaps。它对我有用。


2
投票

如果你使用android:textAllCaps="false",你可以继承appcompat-v7and和AppCompatButton,然后将这个类用于你的所有按钮。

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); } } Android文档。


0
投票

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

由于我的应用程序是针对API少于14而设计的,并且我不想在我的程序中添加代码,所以在我阅读他的答案之前我找不到解决方案。他说的是,即使你已经完成了应用程序样式中所需的操作,除非你为你的活动添加一个样式并且你将textAllCaps设置为false,否则它将无法工作。

仅为活动设置样式是不够的(我的活动有样式),因为样式可能默认为AllCaps属性。您必须在活动中明确地将该属性设置为false。

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


153
投票

这是我在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>

101
投票

通过设置按钮的TransformationMethod,例如,可以在应用程序代码中修复此问题。

mButton.setTransformationMethod(null);

62
投票

设置android:textAllCaps =“false”。如果您使用的是appcompat样式,请确保textAllCaps位于样式之前。否则样式将覆盖它。例如:

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

54
投票

在样式中添加此行

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


31
投票

Lollipop默认带有“textAllCaps true”,因此您必须手动将其设置为false


31
投票

这一个正在工作....只需在底部代码的代码中添加以下代码:

android:textAllCaps="false"

它应该取消U试图输入小的大写字母。


23
投票

<Button>标签中添加android:textAllCaps =“false”就是这样。


19
投票

有一种更简单的方法适用于所有按钮,只需更改主题中按钮的外观,试试这个:

在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:建议遵循材料设计原则,你应该在按钮,qazxsw poi中显示大写文本

© www.soinside.com 2019 - 2024. All rights reserved.