Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过代码同时设置点击效果和按压效果,会出现混乱和无效的情况 #165

Open
Khaos116 opened this issue Apr 6, 2024 · 1 comment

Comments

@Khaos116
Copy link

Khaos116 commented Apr 6, 2024

展示异常
image_2024-04-06_13-01-11

然后可以点击的时候,按压效果只有背景有效,文字按压效果丢失

如果只设置文字的按压效果,不设置是否可以点击的效果,就能正常按压变色

@Khaos116
Copy link
Author

Khaos116 commented Apr 6, 2024

文字颜色应该是少了一个默认的颜色
// 定义不同状态下的颜色值
int[][] states = new int[][] {
new int[] { android.R.attr.state_pressed }, // 按下状态
new int[] { android.R.attr.state_enabled}, // 获取可点击状态
new int[] {} // 默认状态
};

int[] colors = new int[] {
getResources().getColor(R.color.button_pressed_color), // 按下状态颜色
getResources().getColor(R.color.button_fstate_enabled_color), // 获取可点击状态颜色
getResources().getColor(R.color.button_normal_color) // 默认不可以点击状态颜色
};

// 创建ColorStateList
ColorStateList colorStateList = new ColorStateList(states, colors);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant