<pre style="font-family: Menlo; font-size: 12pt; background-color: rgb(255, 255, 255);"><pre name="code" class="java">StateListDrawable drawable = new StateListDrawable();
//普通状态
drawable.addState(new int[]{-android.R.attr.state_focused,-android.R.attr.state_selected,-android.R.attr.state_pressed}
,getDrawableFromAsset(context,normalFile));
//按下状态
drawable.addState(new int[]{android.R.attr.state_pressed,-android.R.attr.state_selected}
,getDrawableFromAsset(context,pressFile));
//“-”号,当XML的设定是false时,就需要使用资源符号的负值来设定。
getDrawableFromAsset(context,normalFile)返回的是一个Drawable对象
使用StateListDrawable实现Android状态栏自定义
本文详细介绍了如何使用StateListDrawable在Android中为控件自定义状态栏,包括普通状态、按下状态的实现及代码示例。
1325

被折叠的 条评论
为什么被折叠?



