brian
brian

Reputation: 6922

How to hide TabWidget of tabhost

I use tabhost in my app. I use below code to add intent:

TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
Resources res = getResources();

intent = new Intent().setClass(this, AActivity.class);
spec = tabHost.newTabSpec("Files").setIndicator("NAS Files", res.getDrawable(R.drawable.ic)).setContent(intent);
tabHost.addTab(spec);

In AActivity, I want to hide the tabs(TabWidget) while the button was clicked. And click two times to show tabs. How can I do it?

Upvotes: 2

Views: 9795

Answers (1)

Kiran Ryali
Kiran Ryali

Reputation: 1371

There are three states for view visibility in Android.

  1. visible Visible on screen; the default value.
  2. invisible Not displayed, but taken into account during layout (space is left for it).
  3. gone Completely hidden, as if the view had not been added.

Below are how you do so programatically.

tabhost.setVisibility( View.VISIBLE );
tabhost.setVisibility( View.INVISIBLE );
tabhost.setVisibility( View.GONE );

So, you can set an OnClickListener on tabHost that modifies the visibility of the view.

private OnClickListener tabClickListener = new OnClickListener() {
    public void onClick(View v) {
        v.setVisibility( View.INVISIBLE );
    }
};

// Somewhere else in your code...
tabhost.setOnClickListener( tabClickListener );

To catch double taps, you can keep a counter of taps on the onClick and expire them after a time threshold.

See this question for more info on the double tap

Read the visibility api doc here

Upvotes: 7

Related Questions