java – android更改选项卡图标
发布时间:2020-12-15 02:32:53 所属栏目:Java 来源:网络整理
导读:我想在状态发生变化时更改标签图标.如果我使用以下xml中的drawable,则一切正常: selector xmlns:android="http://schemas.android.com/apk/res/android" item android:drawable="@drawable/d_selected" android:state_selected="true" / item android:drawa
我想在状态发生变化时更改标签图标.如果我使用以下xml中的drawable,则一切正常:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/d_selected" android:state_selected="true" /> <item android:drawable="@drawable/d_normal" /> </selector> 但是,现在我需要从数据/数据文件夹加载图像,并从这些图像生成可绘制的“d”和“dSel”.使用以下代码仅显示“dSel”,并且不显示其他选项卡图像!谢谢 ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); selector.addState(new int[]{ android.R.attr.state_pressed },d); selector.addState(new int[]{ android.R.attr.state_selected },dSel); selector.addState(new int[]{ android.R.attr.state_focused },d); icon.setImageDrawable(selector); //icon.setImageResource(drawableId); used with other method described,if related to xml 解决方法
最后我找到了解决方案.每个州的真/假由“ – ”处理.
selector.addState(new int[]{ android.R.attr.state_selected },dSel); selector.addState(new int[]{ -android.R.attr.state_selected },d); 有关更多信息,请参阅此链接,Android : How to update the selector(StateListDrawable) programmatically (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |