Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tab bar hiding issue android

I'm new to android,I'm using tabHost adding some tabs to it,its working quite fine but when i rotate my device in landscape mode it also work there fine but i don't need tab bar there because it covers much space and i also have google ads so both of them cover half of the screen and leave a little space for user to interact.All i need is a solution to somehow hide tab bar just like we can do it in iphone to make a bit room for user to interact.I need some solution urgent.Thanks

like image 409
Muhammad imran Avatar asked Dec 12 '22 18:12

Muhammad imran


1 Answers

I think you should wrap your tab widget in any ViewGroup such as LinearLayout or RelativeLayout, and create a static function in your tabActivity to show/hide this wrapper, Here's a little code might be helpful for you.

<LinearLayout
        android:id="@+id/popupTabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone">
        <TabWidget android:id="@android:id/tabs"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent"></TabWidget>
    </LinearLayout>

Now your tab activity should do something like this.

public class TabsView extends TabActivity { 
    public static LinearLayout popupTabs ;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        popupTabs = (LinearLayout) findViewById(R.id.popupTabs);

        // Your other code
        //............
        //............
    }

    // Show Tabs method
    public static void showTabs(){
        popupTabs.setVisibility(ViewGroup.VISIBLE);
    }

    // Hide Tabs method
    public static void hideTabs(){
        popupTabs.setVisibility(ViewGroup.GONE);
    }

}

Now you can call this method statically from any location in your code like this

// hide tab from any activity
TabsView.showTabs();

// hide tab from any activity
TabsView.hideTabs()
like image 152
Adeel Pervaiz Avatar answered Jan 18 '23 23:01

Adeel Pervaiz