Jonah
Jonah

Reputation: 10091

How to Configure the Action Bar in the Layout?

I have a working tabbed interface right now, but the tabs are declared in activity class. I want to move those declarations to an XML layout file. Unfortunately, I haven't been able to find any examples. How can this be done?

Upvotes: 0

Views: 312

Answers (2)

Rajdeep Dua
Rajdeep Dua

Reputation: 11230

I dont think you can add Tabs in the XML file, only TabWidget can be added. TabSpecs have to be created programmatically and added to the TabHost

TabHost tabHost = getTabHost();  // The activity TabHost
TabHost.TabSpec spec;  // Resusable TabSpec for each tab
Intent intent;  // Reusable Intent for each tab

// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ArtistsActivity.class);

// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists",
                  res.getDrawable(R.drawable.ic_tab_artists))
              .setContent(intent);
tabHost.addTab(spec);

Upvotes: 1

Maximus
Maximus

Reputation: 8431

Have you seen this tutorial? It specifically mentions that it shows how to display an Activity in each tab.

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

EDIT - My apologies, I notice that there is only the TabWidget in the XML and the other tabs are declared in the onCreate() method, so this doesn't answer your question.

Upvotes: 0

Related Questions