gpt4 book ai didi

android - 将调色板颜色应用到 f​​ab on pressed 状态

转载 作者:行者123 更新时间:2023-11-29 17:43:54 25 4
gpt4 key购买 nike

有人可以提示我如何将 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 - 将调色板颜色应用到 f​​ab on pressed 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27748248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com