Android开发之Compose基础学习-TabRow指示器的三种基本用法

本文介绍了Android开发中Compose库的TabRow组件,详细讲解了指示器的三种基本使用方法,结合实例代码展示了如何实现TabRow的定制,提升UI交互体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先上图

再看代码

package com.xiayiye5.composefirst.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.material.icons.filled.Delete
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

/*
 * Copyright (c) 2022, [email protected] All Rights Reserved.
 * #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #           
实现了ViewPager的指示器。标题指示器(TitleIndicator)用于每个ViewPager页标题的切换。图标Tab指示器(IconicTabsView)可以让我们将每个tab做成图标。这俩个指示器你可以选择使用。我做了demo,效果非常不错。而且使用简单。推荐使用。项目地址:https://github.com/MoshDev/AndroidIndicators 效果图:如何使用xml布局中创建ViewPager和指示器<?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"     android:orientation="vertical" >     <com.moshx.indicators.title.TitleIndicator         android:textAppearance="?android:attr/textAppearanceMedium"         android:id="@ id/titleIndicator"         android:textColor="@android:color/black"         android:layout_width="300dp"         android:layout_height="wrap_content" />     <com.moshx.indicators.tab.IconicTabsView         android:layout_width="match_parent"         android:id="@ id/iconicTabsView"         android:layout_height="wrap_content" />     <android.support.v4.view.ViewPager         android:id="@ id/viewPager"         android:layout_width="match_parent"         android:layout_height="match_parent" /> </LinearLayout><com.moshx.indicators.title.TitleIndicator>和<com.moshx.indicators.tab.IconicTabsView>你根据你的需要添加。2. java代码中未ViewPager添加指示器ViewPager mViewPager = (ViewPager) findViewById(R.id.viewPager); mViewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));          //创建ViewPager观察者,用于监听ViewPager的切换 final ViewPagerObserver observer = new ViewPagerObserver(mViewPager); //标题指示器 titleIndicator = (TitleIndicator) findViewById(R.id.titleIndicator); observer.addObservableView(titleIndicator);          //tabs指示器 IconicTabsView iconicTabsView = (IconicTabsView) findViewById(R.id.iconicTabsView); iconicTabsView.setIconicTabsEffect(new GreyscaleIconicTabsEffect()); observer.addObservableView(iconicTabsView);ok。完整的实例你可以点击上面的"下载源码"获得。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值