我正在使用一些调整,允许用户通过SD卡上的资源更改我的应用程序的UI。这真的很简单,没有什么特别的,我只是使用“setImageDrawable”或“setImageBitmap”。
http://developer.android.com/reference/android/widget/ImageButton.html
这真的很酷,我所有的用户都很乐意定制UI。
但是现在,我还想更改按钮的按下/聚焦源!
现在,当他们点击它,他们看不到任何东西,他们点击可能10次。更麻烦的是,这不是很直观。
所以我想通过编程改变按下/聚焦状态。。。
你有什么建议吗?
您必须使所有ImageButtons都具有StateListDrawable而不是BitmapDrawables。
ImageButton ib = new ImageButton(this); StateListDrawable sl = new StateListDrawable(); sl.addState(new int[] { android.R.attr.state_enabled }, yourDefaultDrawableHere); sl.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_selected }, yourImageDrawableHere); ib.setImageDrawable(sl);