玩转FragmentTabHost,实现底部导航栏

三步实现

  • 在布局文件下添加FragmentTabHost导航栏(三个注意事项
    1.在其上添加一个FrameLayout--底部变换真正内容在这里展示
    2.FragmentTabHost的id为android:id="@android:id/tabhost"
    3.子布局FrameLayout的id为android:id="@android:id/tabcontent")

    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">

        
    
      
    
        
     
    
    
    
  • Activity继承FragmentActivity或其子布局

  • FragmentTabHost实例实现setup(Context context, FragmentManager manager, int containerId)方法

使用方法
1.实现setup方法后
2.实例化TabHost.TabSpec类,实现

       public TabSpec setIndicator(View view)

View即为底部导航栏的布局
3.将TabSpec实例和对应的内容添加到TabHost

public void addTab(@NonNull TabHost.TabSpec tabSpec, @NonNull Class clss,
@Nullable Bundle args)

你可能感兴趣的:(玩转FragmentTabHost,实现底部导航栏)