Android 有条件地使用选项卡式活动
我正在尝试创建一个应用程序,该应用程序以具有“自定义”布局的活动A开始。从该活动可以输入带有3个选项卡的活动B 我成功地创建了带有选项卡的活动。问题是,只有当该活动也是启动器活动时,才会显示选项卡。如果不是,则不会显示选项卡 第一次我尝试用TabLayout创建选项卡。现在我尝试用TabHost创建选项卡Android 有条件地使用选项卡式活动,android,tabs,launcher,Android,Tabs,Launcher,我正在尝试创建一个应用程序,该应用程序以具有“自定义”布局的活动A开始。从该活动可以输入带有3个选项卡的活动B 我成功地创建了带有选项卡的活动。问题是,只有当该活动也是启动器活动时,才会显示选项卡。如果不是,则不会显示选项卡 第一次我尝试用TabLayout创建选项卡。现在我尝试用TabHost创建选项卡 有人可以寻求帮助吗?在“创建”选项卡的主活动中创建方法 } 对于每个选项卡,我创建了单独的活动,如下所示: public class SearchTab extends Activit
有人可以寻求帮助吗?在“创建”选项卡的主活动中创建方法 } 对于每个选项卡,我创建了单独的活动,如下所示:
public class SearchTab extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_tab);
}
}
项目的xml部分是通过在设计视图中导入TabHost容器创建的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.example.admin.besedilatakt_v5.GlavnaStran">
<TabHost
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabhost">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
在tab的XML文件中,除了显示一些随机文本的TextView小部件外,tab的活动没有什么特别之处。您可以发布代码片段吗?您对代码的哪一部分感兴趣?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.example.admin.besedilatakt_v5.GlavnaStran">
<TabHost
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabhost">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>