android - 无法在 StateListDrawable 中添加状态
问题描述
在适配器类中,我想突出显示视图,但我做不到。以下是我使用的代码:
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[]{-android.R.attr.state_enabled}, new ColorDrawable(Color.CYAN) );
stateListDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, new ColorDrawable(Color.GREEN));
stateListDrawable.addState(new int[]{}, new ColorDrawable(Color.BLACK));
Log.e("State ",""+stateListDrawable.getState().length );
-> 在日志显示状态 0
解决方案
推荐阅读
- vim - 在 Vim 中将 `:vs|term` 映射到单个键没有按预期工作
- angular - 通过将参数传递给服务类来测试订阅功能
- c - Ctrl+C按下时如何恢复正常终端?
- nlp - 为什么转换器编码组件使用 6 个编码器层的堆栈?
- python - 如何在 Visual Studio 代码中让 print() 和 input() 成为不同的颜色?
- python - 为什么它不接受函数中的数据
- asp.net-mvc - Asp.Net Core Web App 从磁盘播放和下载视频
- python - 我想我在更新 heroku 上的机器人时遇到了错误
- java - 线性布局格式一直显示错误,我已经尽我所能但仍然无法正常工作。?
- java - 如何安排任务将每月电子邮件发送到不同的时区?