1

有人可以给我一个提示,我如何将 Palette 类生成的颜色应用于按下状态的 fab 按钮?
我正在使用侦听器来获取此处public void setPalette(Palette palette)描述的生成颜色,我可以在操作中应用默认状态背景颜色,fab.setBackgroundColor(palette.get...())但我不知道是否有设置按下状态背景颜色的方法,或者如果我必须在 fab 上使用 OnClick 或 OnTouch 侦听器来为事件设置适当的背景颜色。

4

1 回答 1

3

嘿,我知道这已经晚了,但它可能会帮助某人

您执行以下变量声明

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));

你都完成了,我花了很多时间寻找这个。希望它可以帮助某人。

于 2015-07-06T23:27:35.073 回答