三步實(shí)現(xiàn)
-
在布局文件下添加FragmentTabHost導(dǎo)航欄(三個(gè)注意事項(xiàng)
1.在其上添加一個(gè)FrameLayout--底部變換真正內(nèi)容在這里展示
2.FragmentTabHost的id為android:id="@android:id/tabhost"
3.子布局FrameLayout的id為android:id="@android:id/tabcontent")
<?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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.wws.admin.cnscwwstest.MainActivity"><FrameLayout android:id="@+id/real_content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> <android.support.v4.app.FragmentTabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="0"/> </android.support.v4.app.FragmentTabHost> </LinearLayout>
Activity繼承FragmentActivity或其子布局
FragmentTabHost實(shí)例實(shí)現(xiàn)setup(Context context, FragmentManager manager, int containerId)方法
使用方法
1.實(shí)現(xiàn)setup方法后
2.實(shí)例化TabHost.TabSpec類哎甲,實(shí)現(xiàn)
public TabSpec setIndicator(View view)
View即為底部導(dǎo)航欄的布局
3.將TabSpec實(shí)例和對(duì)應(yīng)的內(nèi)容添加到TabHost
public void addTab(@NonNull TabHost.TabSpec tabSpec, @NonNull Class<?> clss,
@Nullable Bundle args)