在 API 21 上,MaterialButton 中工具栏项目的颜色错误。

huangapple go评论87阅读模式
英文:

Wrong color in toolbar items MaterialButton on Api 21

问题

我在AppCompatActivity的工具栏上设置了几个Material样式的按钮作为ActionMenuItem。然而,颜色在仅限于Api 21(Android 5)上显示错误。
[![在Api >21上的外观][1]][1]
[1]: https://i.stack.imgur.com/YN9fO.png
[![Api 21][2]][2]
[2]: https://i.stack.imgur.com/nNNMD.png
其他按钮是禁用的,但基本上它们应该是蓝色的,但在Api 21上却是红色的。
我是这样设置颜色的:

 buttonAction.setBackgroundTintList(menuItem.getColor(context));
 buttonAction.setStrokeColor(menuItem.getColor(context));
 buttonAction.setTextColor(menuItem.getColor(context));
英文:

I have a few Material buttons as ActionMenuItem set on a toolbar in AppCompatActivity. The colors however are wrong only on Api 21 (Android 5).
[![How it looks on Api >21][1]][1]
[1]: https://i.stack.imgur.com/YN9fO.png
[![Api 21][2]][2]
[2]: https://i.stack.imgur.com/nNNMD.png
The other buttons are disabled but basically they should be blue but are red on Api 21.
I'm setting the colors like this

 buttonAction.setBackgroundTintList(menuItem.getColor(context));
 buttonAction.setStrokeColor(menuItem.getColor(context));
 buttonAction.setTextColor(menuItem.getColor(context));

答案1

得分: 0

我设法自行解决了这个问题。问题出在默认背景设置为?attr/colorPrimary。我为 API 21 创建了新的颜色 XML,并将其设置为 @color/colorPrimary。我不知道这是否是最佳解决方案。如果有更好的答案,请写下来。

英文:

I managed to fix it myself. The problem was the default background was set with
?attr/colorPrimary. I made new colors xml for API 21 and set it like this @color/colorPrimary. I don't know if it's the best fix. If anyone has a better answer please write it.

huangapple
  • 本文由 发表于 2020年4月9日 15:56:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/61116428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定