Android 固定 Tab 位于底部
我希望底部有固定选项卡,这样我就可以在每个活动中使用相同的选项卡。我有一个在底部显示选项卡的布局,但如何在其上方添加 TextView ?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec tabSpec;
Intent intent;
Resources resources = getResources();
intent = new Intent(MainActivity.this, FirstActivity.class);
tabSpec = tabHost.newTabSpec("tab1");
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
intent = new Intent(MainActivity.this, SecondActivity.class);
tabSpec = tabHost.newTabSpec("tab2");
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
}
这是我的 TabActivity。我有 ThirdActivity ,其布局是这样的(似乎不是,但 TextView 在relativelayout中):
<?xml version="1.0" encoding="UTF-8"?>
TextView
android:id="@+id/text"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
我希望 ThirdActivity 应该包含选项卡“tab1”和“tab2”。
I want fixed tabs at bottom such I can use the same tabs in each activity. I have a layout that shows the tabs at bottom but how can I add TextView above of that?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec tabSpec;
Intent intent;
Resources resources = getResources();
intent = new Intent(MainActivity.this, FirstActivity.class);
tabSpec = tabHost.newTabSpec("tab1");
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
intent = new Intent(MainActivity.this, SecondActivity.class);
tabSpec = tabHost.newTabSpec("tab2");
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
}
This is my TabActivity. And I have ThirdActivity whose layout is like that(It does not seem but TextView is in RelativeLayout) :
<?xml version="1.0" encoding="UTF-8"?>
TextView
android:id="@+id/text"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
And I want ThirdActivity should contain the tabs "tab1" and "tab2".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 中的教程上面的链接由 Dipak 发布,用于创建 TabHost 的布局。
然后继续创建一个类来处理 TabActivity 并为每个选项卡创建 3 个单独的活动类。将它们与上述布局链接起来。
教程向您展示如何创建选项卡主机。
Use the tutorial in link above posted by Dipak, to create the layout of the TabHost.
Then go ahead an create a class to handle the TabActivity and create 3 separate activity classes for each of your tabs. Link these with the layout described above.
There is a tutorial here showing you how you can create a tab host.
我认为@adaclks希望使选项卡栏
对所有活动保持一致
......这意味着每当您想要打开任何新活动或子活动时,您都需要将标签栏保留在每个活动的底部。如果我没记错的话,那么你可以使用
ActivityGroup
概念,由于此类已弃用,您可以使用
片段
和FragementManager
API 代替。以下是 ActivityGroup 的示例: 在TabHost中使用Android ActivityGroup来显示不同的Activity
I think @adaclks want to make Tab bar
consistent for all the activities
.....it means that whenever you want to open any new activity or child activity, you want to keep tab bar at bottom in every activity.If i am not wrong, then you can use
ActivityGroup
concept, as this class is deprecated, you can useFragment
andFragementManager
API instead.Here is an example for ActivityGroup: Use Android ActivityGroup within TabHost to show different Activity