是否可以在TabHost制作的标签中创建子标签?如果是这样,怎么样?在这种情况下,我无法找到任何有价值的资源或帮助。
由于
答案 0 :(得分:2)
可以在TabActivity
内添加Tab
。
假设您MainTabActivity
有两个Tabs
。然后,第一个Tab
可以保留FirstSubTabActivity
,第二个Tab
可以保留SecondSubTabActivity
。
以下是一个例子:
主要活动:
public class MainTabActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass( this, FirstSubTabActivity.class );
spec = tabHost.newTabSpec( "FirstTab" ).setIndicator( "One" ).setContent( intent );
tabHost.addTab( spec );
intent = new Intent().setClass( this, SecondSubTabActivity.class );
spec = tabHost.newTabSpec( "SecondTab" ).setIndicator( "Two" ).setContent( intent );
tabHost.addTab( spec );
}
}
第一次子活动:
public class FirstSubTabActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass( this, SomeActivity.class );
spec = tabHost.newTabSpec( "SubTab" ).setIndicator( "One" ).setContent( intent );
tabHost.addTab( spec );
intent = new Intent().setClass( this, SomeOtherActivity.class );
spec = tabHost.newTabSpec( "AnotherSubTab" ).setIndicator( "Two" ).setContent( intent );
tabHost.addTab( spec );
}
}
第二次子活动:
public class SecondSubTabActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass( this, SomeThirdActivity.class );
spec = tabHost.newTabSpec( "ThirdSubTab" ).setIndicator( "One" ).setContent( intent );
tabHost.addTab( spec );
intent = new Intent().setClass( this, SomeFourthActivity.class );
spec = tabHost.newTabSpec( "FourthSubTab" ).setIndicator( "Two" ).setContent( intent );
tabHost.addTab( spec );
}
}