作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有人可以提示我如何将 Palette 类生成的颜色应用于按下状态的 fab-button 吗?
我正在使用监听器来获取所描述的生成的颜色 here ,我可以在 public void setPalette(Palette palette)
中应用默认状态背景色使用 fab.setBackgroundColor(palette.get...())
的操作但我不知道是否有设置按下状态背景颜色的方法,或者我是否必须在 fab 上使用 OnClick 或 OnTouch 监听器来为事件设置适当的背景颜色。
最佳答案
嘿,我知道这已经晚了,但它可能对某人有帮助
你做下面的变量声明
int[][] states = new int[][] {
new int[] { android.R.attr.state_enabled}, // enabled
new int[] {-android.R.attr.state_enabled}, // disabled
new int[] {-android.R.attr.state_checked}, // unchecked
new int[] { android.R.attr.state_pressed} // pressed
};
int[] colors = new int[] {
Color.RED,
Color.BLUE,
Color.GREEN,
Color.YELLOW
};
(Button) btn = (Button) findViewById(R.id.fab).setBackgroundTintList(new ColorStateList(states, colors));
你都完成了,我花了很多时间来寻找这个。希望对某人有所帮助。
关于android - 将调色板颜色应用到 fab on pressed 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27748248/
我是一名优秀的程序员,十分优秀!