Mar*_*tin 9 android android-layout android-tabhost android-tabactivity
看来TabActivity现已弃用,我们需要使用Fragments.
我尝试使用标准的Activity但无法调用getTabHost.
所以看来我必须使用Fragments.但我有点困惑这是如何工作的.
我知道片段不是活动所以它们不在清单文件中?
所以我认为我不能对片段做startActivity?
有没有人知道解释tabHost和Fragments的一个很好的例子,我发现的所有例子和教程都只使用了tabactivity.
提前致谢
今天 Android 为这些提供了很好的教程。从使用选项卡创建滑动视图开始
这是如何创建选项卡的小快照
@Override
public void onCreate(Bundle savedInstanceState) {
final ActionBar actionBar = getActionBar();
...
// Specify that tabs should be displayed in the action bar.
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create a tab listener that is called when the user changes tabs.
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// show the given tab
}
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
// hide the given tab
}
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
// probably ignore this event
}
};
// Add 3 tabs, specifying the tab's text and TabListener
for (int i = 0; i < 3; i++) {
actionBar.addTab(
actionBar.newTab()
.setText("Tab " + (i + 1))
.setTabListener(tabListener));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28283 次 |
| 最近记录: |