Android的tabactivity - 如何改变选择标签图标图像 [英] Android tabactivity - how to change icon image on selecting a tab
问题描述
在我tabactivity,我显示图标,我从数据库中获取,通过创建一个ImageView的和passsing这给setIndicator方法。我只有一个图像的每个选项卡上,所以我想知道是否有办法只是改变单独图像的颜色(而不是改变标签的颜色)当选择一个标签?也有可能隐藏在选择一个选项卡正被在标签底部绘制的灰线?
任何帮助是AP preciated..thanks
In my tabactivity, I display icon that I get from the database, by creating an ImageView and passsing this to the setIndicator method. I have only one image for each tab, so I was wondering if there is way to just change the color of the image alone (as opposed to changing the tab's color) when a tab is selected? Also is it possible to hide the gray line that is being drawn at the bottom of the tabs when a tab is selected? Any help is appreciated..thanks
推荐答案
隐藏灰线:
yourTabWidget.setStripEnabled(false);
每个标签状态设置自定义图片:
Setting custom image per tab state:
tabitemicon.xml:
tabitemicon.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/orange"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/white" />
</selector>
Java的code:
Java code:
tabHost = getTabHost():
tabHost.newTabSpec("test").setIndicator("My Tab Title",
res.getDrawable(R.drawable.tabitemicon))
.setContent(someIntent);
这篇关于Android的tabactivity - 如何改变选择标签图标图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!