从Appcompat 22.2.0编程方式更改浮动操作按钮的颜色 [英] Change color of Floating Action Button from Appcompat 22.2.0 programmatically
本文介绍了从Appcompat 22.2.0编程方式更改浮动操作按钮的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何改变从支持库22.2.0浮动操作按钮的颜色? 我试过
I would like to know how to change the Floating Action Button color from the Support library 22.2.0 ? I've tried
button.setBackgroundColor(color);
但很明显,这改变了按钮的绘制,并将其变成一个正方形。
but clearly, this changes the drawable of the button and it turns to a square.
现在我不知道如何改变颜色,但仅仅是颜色,不接触的形状?
Now I wonder how to change the color but just the color, without touching the shape?
在此先感谢
推荐答案
创建一个 ColorStateList
,并将其设置为背景色调:
Create a ColorStateList
and set it as the background tint:
button.setBackgroundTintList(new ColorStateList(new int[][]{new int[]{0}}, new int[]{color}));
这篇关于从Appcompat 22.2.0编程方式更改浮动操作按钮的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文