In my app I use the tabhost to create a menu bar like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
</LinearLayout>
And
tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
tabHost.addTab(tabHost.newTabSpec("home").setIndicator("Home"),HomeFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("attraction").setIndicator("Attraction"),AttractionFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("schedule").setIndicator("Schedule"),ScheduleFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("map").setIndicator("Map"),MapViewFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("weather").setIndicator("Weather"),WeatherFragment.class, null);
The problem is , when the keyboard is show , the tabbar is above the keyboard , I have set the input mode like that:
android:windowSoftInputMode="stateHidden"
How to hide the tabbar when keyboard shows? Thanks
onConfigurationChanged method can be overridden to handle run-time changes you can use tabHost.setVisibility( View.GONE ); Handling Runtime Change
// from the link above
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks whether a hardware keyboard is available
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
tabHost.setVisibility( View.GONE );
}
else if (newConfig.hardKeyboardHidden ==Configuration.HARDKEYBOARDHIDDEN_YES) {
tabHost.setVisibility( View.VISIBLE );
}
}
you can add this piece of code on each activity where you want to hide the tabhost,you just need to pass the Rootview id of your layout.
public final int SOFTKEYBOARDHEIGHT=100;
final View activityRootView = findViewById(R.id.YOURROOTVIEW);
activityRootView.getViewTreeObserver()
.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > SOFTKEYBOARDHEIGHT) {
tabHost.setVisibility( View.GONE );
}
}
});