简体   繁体   English

如何在Android应用程序的每个标签中添加唯一内容

[英]How do I add unique content to each tab in an Android app

I'm trying to make an app that has three tabs, each with different but linked content. 我正在尝试制作一个具有三个选项卡的应用程序,每个选项卡具有不同但链接的内容。 Currently, I want some features to appear on one tab but not on another. 目前,我希望某些功能显示在一个选项卡上,而不显示在另一个选项卡上。 For example, I would like a SeekBar to be displayed on only one of the tabs. 例如,我希望SeekBar仅显示在一个选项卡上。 But, currently, it is displayed for all of them. 但是,目前,所有这些都显示出来。

I greatly appreciate any help 我非常感谢您的帮助

It seems like you want to dynamically add content to the TabHost . 似乎您想将内容动态添加到TabHost You will be able to add different tabs to the TabActivity once it is created based on a variable. 一旦基于变量创建TabActivity,就可以将其添加到TabActivity中。 Here is an example ... 这是一个例子...

TabHost host = findViewById(R.id.my_tabhost);
boolean boo = true; //Variable that will decide what tabs to add
host.setup(); //Need to call before adding tabs
if (boo)
    host.addTab(host.newTabSpec("Hello").setIndicator("Hello").setContent(new Intent(this, HelloActivity.class)));
else
    host.addTab(host.newTabSpec("Goodbye").setIndicator("Goodbye").setContent(new Intent(this, GoodbyeActivity.class));

This way the tabs will be different if boo is true or if boo is false. 这样,如果bootrue或boo为false,选项卡将有所不同。 Then you can add your content to HelloActivity and GoodbyeActivity . 然后,您可以将您的内容HelloActivityGoodbyeActivity

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在android中,如何在每个标签内创建不同的片段/活动堆栈,这些片段/活动堆栈会在所有标签更改之间持续存在? - In android how do I create different fragments/activities stacks within each tab that persist across tab changes? Android:如何向现有应用添加标签栏 - Android: how to add a tab bar to the existing app 如何从Web / JavaScript生成唯一ID,然后在android App中生成相同的唯一ID? - How do I generate a unique ID from web/javascript and then generate same unique ID in android App? Android将内容添加到“自定义”标签 - Android Add content to Custom Tab 如何为Android应用程序的每个用户创建唯一的ParseObject? - How can I create a unique ParseObject for each user of my Android App? 如何让每个 ListView 元素创建一个独特的活动 [Android Studio - Kotlin] - How do I make each ListView element create a unique activity [Android Studio - Kotlin] 如何添加到我在Android应用程序上创建的文件? - How do I add to the file i created on my android app? 选择其他选项卡后,如何更改内容视图? (相关的Android HoneyCombGallery示例) - How do I change the content view when a different tab is selected? (Android HoneyCombGallery example related) Android操作栏标签:每次单击该标签时,都会重新创建每个标签的内容 - Android actionbar tabs: content of each tab is recreated everytime I click on that tab 如何在TabbedActivity Android中的操作栏中向每个选项卡添加图标 - How to add icons to each tab in action bar in TabbedActivity Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM