kotlin 实现安卓底部导航栏(点击变换图标和文字)+Fragment切换

这篇博客详细介绍了如何使用Kotlin在Android Studio中实现底部导航栏,包括点击按钮时图标和文字颜色的变化,以及与之对应的Fragment的切换。文章分为四个部分:布局逻辑,XML布局代码,Kotlin代码实现图标和文字变换,以及Fragment的切换方法。通过实例化控件,设置点击事件和Fragment替换方法,成功实现了功能。
  1. 布局逻辑
  2. 布局代码
  3. .kt代码实现点击后图标和文字变换
  4. 实现点击后Fragment切换

效果图

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

一、布局逻辑

在这里插入图片描述

二、布局XML代码

<?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:gravity="center_horizontal"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Top"
        android:layout_gravity="center_horizontal"
        android:textColor="#000000"
        android:textSize="40sp"/>

    <RelativeLayout
        android:id="@+id/mainbody"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/frag"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/bottom_bar">
        </FrameLayout>

        <LinearLayout
            android:id="@+id/bottom_bar"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal"
            android:layout_alignParentBottom="true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值