Kotlin ViewPager与Fragment实现一页多状态效果?

本文介绍如何使用Kotlin配合ViewPager在Android应用中实现一页展示多个状态的效果。详细步骤包括Build中添加相关引用,设置activity_main.xml布局,创建Fragment的adapter,以及在主Activity中进行配置。此外,还提到了自定义Fragment和使用app:tabSelectedTextColor等属性来改变选中状态的字体颜色。
摘要由CSDN通过智能技术生成

一、效果图

      

 

二、实现步骤

1.Build中添加引用

//viewpager2
implementation "androidx.viewpager2:viewpager2:1.0.0"
//tab
implementation 'com.google.android.material:material:1.2.1'

2.布局activity_main.xml 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/color_white"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#0361CE"
        android:minHeight="160px">

        <ImageView
            android:id="@+id/img_zhxz_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20px"
            android:src="@mipmap/img_back"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yyxhzdm

你的鼓励是我创作的最大动力!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值