我现在有一个工作标签界面,但是标签在活动类中声明。我想将这些声明移动到XML布局文件。不幸的是,我找不到任何例子。怎么办呢?
答案 0 :(得分:1)
我认为你不能在XML文件中添加Tabs,只能添加TabWidget。必须以编程方式创建TabSpec并将其添加到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);
答案 1 :(得分:0)
你看过这个教程吗?它特别提到它显示了如何在每个选项卡中显示活动。
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
编辑 - 我很抱歉,我注意到XML中只有TabWidget,其他选项卡在onCreate()方法中声明,所以这不能回答你的问题。