Balban
Balban

Reputation: 736

How can we make Tab layout auto hide?

generally we can hide particular tabs at runtime. but I need to make make whole tab layout hideable. when I click the screen once it appears and other time it will disappear. Can this possible. I have seen this in motorola Droid X phone's camera application. please Help me. thanks in advance

Upvotes: 1

Views: 962

Answers (2)

cdhabecker
cdhabecker

Reputation: 1703

This example uses a TabActivity. The key point is to make its TabWidget invisible.

public class MainActivity extends TabActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Resources resources = getResources();
        TabHost host = getTabHost();
        TabHost.TabSpec spec;
        spec = host.newTabSpec("one")
            .setIndicator(getText(R.string.oneTabIndicator),
                    resources.getDrawable(R.drawable.ic_tab_one))
            .setContent(new Intent().setClass(this, OneActivity.class));
        host.addTab(spec);
        OneActivity child = (OneActivity)getLocalActivityManager().getActivity("one");
        child.registerParentActivity(this);
            // and so on for other tabs
    }

    public void toggleTabs() {
        TabWidget tab = getTabHost().getTabWidget();
        int visibility = View.GONE;
        if (tab.getVisibility() == View.GONE) {
            visibility = View.VISIBLE;
        }
        tab.setVisibility(visibility);
    }

}

And...

public class OneActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        // ...
        Button button = (Button)findViewById(R.id.toggleButton);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                doToggle();
            }
        });
    }

    private void doToggle() {
        ((MainActivity)myParentActivity).toggleTabs();
    }

    public void registerParentActivity(Activity parent) {
        myParentActivity = parent;
    }
}

You just need to decide on the mechanism that you want to use to call your version of toggleTabs().

Upvotes: 0

Friz14
Friz14

Reputation: 278

you can use the setVisibility(8); :)

you put an Id in your linearLayout and manage it in the code with:

LinearLayout l=(LynearLayout) findViewById(R.id.myId);
l.setOnClickListener(this);

public void OnClick(View v){
    myTab.setVisibility(View.GONE);
}

Upvotes: 1

Related Questions