如何更改TabHost的标签图片 [英] How to change the Tabs Images in the TabHost

查看:107
本文介绍了如何更改TabHost的标签图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用的是TabHost在我的应用程序,我使用的四个选项卡在我的应用程序,我想使用不同的图像在TabHost当特定选项卡中被选中,而不是选择。我需要使用不同的图像的每一个特定的标签。

I am using the TabHost in my application, I am using four Tabs in my application and I want to use the different Images in the TabHost when the Particular Tab is been Selected and not selected. I need to use to different Images for a particular tab each.

当我选择任何选项卡上的图片是小亮,当我切换到另一个标签在明亮的图像变成灰色阴影。

When I Select any Tab the Image is little bright and when I switch to another Tab that bright Image becomes grey shaded.

我已经实现了TabHost但我不知道如何改变图像的TabHost。

I have implemented the TabHost but I don know how to change the Images in the TabHost.

任何人可以帮助我在这。

Can anybody help me in this.

谢谢, 大卫

推荐答案

如果你想使用不同的图像选择和未选中状态,然后创建一个在您可绘制文件夹选择XML文件为每个标签,如: tab1_selector.xml,tab2_selector.xml应包含以下内容,更换绘制引用您的图片选择和未选中状态。即。

If you wish to use different images for the selected and unselected states, then create 'selector' XML files in your drawables folder for each tab, e.g. tab1_selector.xml, tab2_selector.xml which should contain the following, replacing the drawable references to your images for selected and unselected states. i.e.

    <?xml version="1.0" encoding="utf-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:state_selected="true"
    android:drawable="@drawable/tab1_selected_image" />
  <item
    android:state_selected="false"
    android:drawable="@drawable/tab2_unselected_image" />
</selector>

然后用.setIndicator方法bharath上面写的是要参考你的新的XML绘制资源。

Then using the .setIndicator method as bharath wrote above you should reference your new xml drawable resource.

这篇关于如何更改TabHost的标签图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆