I am implementing nested fragments in my app using the new API 17, which provides a FragmentTabHost for doing so. However, I’m having trouble with a few basic things for my simple 2 tab fragments inside a parent fragment:
- I would like the nested tabs to be at the bottom (View1 and View2 tabs)
- I would like to customize the actual tabs to look different than standard

Has anyone worked with these before and know how to achieve this? Here’s the sample code which I have up and running:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class FragmentTabsFragmentSupport extends Fragment {
private FragmentTabHost mTabHost;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mTabHost = new FragmentTabHost(getActivity());
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.fragment1);
mTabHost.addTab(mTabHost.newTabSpec("Tab1").setIndicator("Simple"),
NestedFragment1.class, null);
mTabHost.addTab(mTabHost.newTabSpec("Tab2").setIndicator("Contacts"),
NestedFragment2.class, null);
return mTabHost;
}
@Override
public void onDestroyView() {
super.onDestroyView();
mTabHost = null;
}
}
I have tried the following to bottom align the tabs, but no luck:
TabWidget mTabWidget = mTabHost.getTabWidget();
mTabWidget.setGravity(Gravity.BOTTOM);
mTabWidget.setVerticalGravity(Gravity.BOTTOM);
I finally got to the bottom of this. There is an issue with FragmentTabHost.java which will always create a TabHost element for you, no matter what you define in XML and inflate beforehand.
As such, I commented out that part of code when writing my own version of FragmentTabHost.java.
Make sure to use your new version of this in your XML layout,
<com.example.app.MyFragmentTabHostAnd of course inflate it:
Fragment1.java:
MyFragmentTabHost.java: