效果如图:
实现可最基本的导航栏功能,不能左右滑动,只能点击
1.内嵌的fragment的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="50sp"
android:textColor="@color/colorPrimary"
android:text="home"/>
</LinearLayout>
2.fragment的activity代码:
public class FrHome extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.fragment_home, container, false);
return view;
}
}
以此为例根据需要编写不同的fragment布局等等。
3.装载fragment的界面布局如下(其中使用了selector进行实现点击改变图标和文字颜色):
点击改变文字颜色:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#3F51B5"/>
<item android:state_checked="false" android:color="#8f8f8f"/>
</selector>
点