英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论