为什么我的Button文本被迫在Lollipop上全部大写?

本文翻译自:Why is my Button text forced to ALL CAPS on Lollipop?

In my app "Tide Now WA" which I recently tested for compatibility using the new Nexus 9 tablet (Lollipop - API 21). 我最近在我的应用“ Tide Now WA”中使用新的Nexus 9平板电脑(Lollipop-API 21)测试了兼容性。

It writes some button text. 它写入一些按钮文本。 This app writes the text correctly using Android 2.3 and Android 4.0. 此应用使用Android 2.3和Android 4.0正确写入文本。 Ie mixed capital and lower case letters. 即混合使用大写和小写字母。

When same app is run on my Nexus 9 all the letters in the text are capitalized. 在Nexus 9上运行相同的应用程序时,文本中的所有字母均大写。

FWIW my manifest contains the following statement: FWIW我的清单包含以下语句:

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

Can I fix this in my code or is it a bug in the OS thanks 我可以在代码中解决此问题,还是操作系统中的错误?


#1楼

参考:https://stackoom.com/question/1p7F7/为什么我的Button文本被迫在Lollipop上全部大写


#2楼

I don't have idea why it is happening but there 3 trivial attempts to make: 我不知道为什么会这样,但是有3次尝试:

  1. Use android:textAllCaps="false" in your layout-v21 在您的layout-v21使用android:textAllCaps="false"

  2. Programmatically change the transformation method of the button. 以编程方式更改按钮的转换方法。 mButton.setTransformationMethod(null);

  3. Check your style for Allcaps 检查您的Allcaps风格

Note : public void setAllCaps(boolean allCaps) , android:textAllCaps are available from API version 14. 注意public void setAllCaps(boolean allCaps)android:textAllCaps 从API版本14获得。


#3楼

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


#4楼

OK, just ran into this. 好,就碰到这个 Buttons in Lollipop come out all uppercase AND the font resets to 'normal'. Lollipop中的按钮全部大写,并且字体重置为“正常”。 But in my case (Android 5.02) it was working in one layout correctly, but not another!? 但是就我而言(Android 5.02),它在一种布局中正常工作,而在另一种布局中却不行!

Changing APIs didn't work. 更改API无效。
Setting to all caps requires min API 14 and the font still resets to 'normal'. 设置为全部大写都需要至少API 14,并且字体仍会重置为“正常”。

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). 这是因为,如果未定义Android材质样式,则会强制更改样式(这就是为什么它可以在我的一种布局中工作,而在另一种布局中却不能工作,因为我定义了一种样式)。

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" android:theme =“ @ android:style / Theme.NoTitleBar.Fullscreen”
(hope this helps someone, would have saved me a couple of hours last night) (希望这可以帮助某人,昨晚可以为我节省几个小时)


#5楼

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

mButton.setTransformationMethod(null);

#6楼

If you have arrived here because your facebook button text appears in all caps then just add this android:textAllCaps="false" in your xml file. 如果您因为Facebook按钮文本全部大写而到达此处,则只需在xml文件中添加此android:textAllCaps="false" It worked for me. 它为我工作。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值