“取消选择”一个在TabHost标签 [英] 'Unselect' a tab in a TabHost
问题描述
我有一个TabHost持有5个选项卡。 据我所看到的,必须有一个选项卡始终选择。
I have a TabHost holding 5 tabs. As far as I can see, there has to be one tab selected at all times.
我需要一种方法来取消选择所有的标签,以便没有人会被选中。
I need a way to unselect all my tabs so none will be selected.
如果该tabhost是由一般意味着有一个标签在任何时候选择, 我怎样才能让它出现(UI而言),如果标签没有被选中?
If the tabhost is meant by general to have one tab selected at all times, how can I make it appear (UI speaking) as if the tab isn't selected?
推荐答案
这是不可能的AFAIK。但是,是的,你可以设置所选择的选项卡的颜色看起来就像是选择,而当你想它正常显示,以用户设置的留白的布局设计在它通过管理,当你把它未选中,并设立正常布局的全局变量。但是,这是怎样的一个把戏。
This is not possible AFAIK. but yes,you can set the selected tab's color to look like it is unselected and set a blank layout over it by managing a global variable when you make it 'unselected' and setting up normal layout when you want it to be shown normally to user. But this is kind of a trick.
希望,你明白我的意思!
Hope,you get my point!
编辑:
假设你已经设定字符串什么=消失
放在你的code,以显示其未选择的,然后就可以使用这个功能来改变颜色标签:
Suppose you have set String what="disappear"
somewhere in your code to show it 'unselected',then you can use this function to change color of tab:
Main.class:
//Change The Backgournd Color of Tabs
public void setTabColor(TabHost tabhost) {
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
{
tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FFFFFF"))); //unselected white colored
}
if(!what.equals("disappear"))
tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("FF0000"))); // selected red colored
else
tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("FFFFFF"))); // selected but show as unselected with white color
}
而在你的活动类(这是由选定的选项卡打开):
And in your activity class(which is opened by that selected tab):
FirstActivity.class:
if(what.equals("disappear"))
setContentView(R.layout.blank);
else
setContentView(R.layout.first_layout);
blank.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/layout"
android:background="#ffffff"
android:gravity="center">
<!-- You can make background transperent by setting it to "00ffffff" -->
<!-- You can also add this textview to guide user -->
<!--
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click Any Tab To Start
/>
-->
</LinearLayout>
这篇关于“取消选择”一个在TabHost标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!