0

我需要一遍又一遍地以编程方式制作 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);
4

1 回答 1

0

不用担心,如果您以编程方式创建 StateListDreawable 对象,它不会生成 xml 文件。如果您只想将状态添加到可绘制的状态列表中,那么您的代码是完美的。

于 2016-08-08T12:48:06.250 回答