我需要一遍又一遍地以编程方式制作 StateListDrawable(当用户选择按钮时)。但是,我担心每次发生这种情况时都会生成新的 XML 文件。如何确保以前的 XML 文件被破坏和/或替换?
我的代码,截至目前:
StateListDrawable states = new StateListDrawable();
states.addState(new int[] {android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.item_tap_state));
states.addState(new int[]{}, new BitmapDrawable(getResources(), newItem));
item.setImageDrawable(states);