Is it possible to add a tabhost in an activity that has an action bar ? I want it to look like this:
|--------------------------------------|
|< Title ActionBar Settings|
|--------------------------------------|
| |
| |
| |
| |
| Tab 1 Content |
| |
| |
| |
| |
|--------------------------------------|
| Tab 1 | Tab 2 | Tab 3 |
|--------------------------------------|
The reason I don't want to use ActionBar tabs because they do not support bottom tabs. I am using bottom tabs as mentioned in this question here: Android: Tabs at the BOTTOM
And I still want to use ActionBar.
Can this be done ?
Edit:
Here is the code I am using
public class TabsFragment extends Fragment {
public TabsFragment() {
}
private TabHost mTabHost;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Intent i = new Intent(getActivity(), Timeline.TimelineFragment.class);
View view = inflater.inflate(R.layout.activity_tab_host, container, false);
mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
mTabHost.setup();
TabHost.TabSpec tab = mTabHost.newTabSpec("my tab content");
tab.setIndicator("my tab content");
tab.setContent(i);
mTabHost.addTab(tab);
mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
return view;
}
}
And TimelineFragment. The fragment_timeline.xml contains normal views.
public static class TimelineFragment extends Fragment {
public TimelineFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_timeline, container, false);
return rootView;
}
}
And this is the activity that is called on launch:
public class TabsFragmentActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabs_fragment);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new TabsFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.tabs, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
This code is giving me error:
05-02 20:04:14.525: E/AndroidRuntime(2884): Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
05-02 20:04:14.525: E/AndroidRuntime(2884): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:747)