首页 > 解决方案 > 无法在 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

标签: androidandroid-layout

解决方案


推荐阅读