使用RadioGroup实现底部导航栏

本文介绍如何利用RadioGroup在Android中实现底部导航栏功能,通过内嵌Fragment和使用Selector实现点击切换Fragment并改变图标和文字颜色。同时,文中还提及了双击返回键退出应用的设置。
摘要由CSDN通过智能技术生成

效果如图:

实现可最基本的导航栏功能,不能左右滑动,只能点击

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值