iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Android TabLayout选项卡如何使用
  • 877
分享到

Android TabLayout选项卡如何使用

2023-07-05 21:07:48 877人浏览 安东尼
摘要

这篇“Android TabLayout选项卡如何使用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Android

这篇“Android TabLayout选项卡如何使用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Android TabLayout选项卡如何使用”文章吧。

Android TabLayout选项卡如何使用

TabLayout

TabLayout 在开发中一般作为选项卡使用,常与 ViewPager2 和Fragment 结合起来使用。

常用属性:

Android TabLayout选项卡如何使用app:tabBackground 设置 TabLayout 的背景色,改变整个TabLayout 的颜色;

Android TabLayout选项卡如何使用app:tabTextColor 设置未被选中时文字的颜色;

Android TabLayout选项卡如何使用app:tabSelectorColor 设置选中时文字颜色;

Android TabLayout选项卡如何使用app:tabTextAppearance="@android:style/TextAppearance.Large" 设置 TabLayout 的文本主题,无法通过 textSize 来设置文字大小,只能通过主题来设定;

Android TabLayout选项卡如何使用app:tabMode="scrollable"设置 TabLayout 可滑动,当 tabItem 个数较多时,一个界面无法呈现所有的导航标签,此时就必须要用;

Android TabLayout选项卡如何使用app:tabIndicator 设置指示器;

Android TabLayout选项卡如何使用app:tabIndicatorColor 设置指示器颜色;

Android TabLayout选项卡如何使用 app:tabIndecatorHeight 设置指示器高度,当app:tabIndecatorHeight="0dp",隐藏 Indicator 效果;

Android TabLayout选项卡如何使用app:tabTextAppearance="@android:style/TextAppearance.Holo.Large" 改变 TabLayout 里 TabItem 文字的大小;

Android TabLayout选项卡如何使用app: tabpadding 设置 Tab 内部 item 的 padding。也可以单独设置某个方向的padding, 比如 app:tabPaddingStart 设置左边距;

Android TabLayout选项卡如何使用app:paddingEdng / app:paddingStart 设置整个 TabLayout 的 padding;

Android TabLayout选项卡如何使用app:tabGravity="center" 居中,如果是 fill,则充满;

Android TabLayout选项卡如何使用app:tabMaxWidth / app:tabMinWidth 设置最大/最小的 tab 宽度,对 Tab 的宽度进行限制。

TabItem

给TabLayout 添加 Item 有两种方法,其中一种就是使用 TabItem 在 xml 里直接添加。

使用TabItem 给 TabLayout 添加卡片。

<com.Google.android.material.tabs.TabItem     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:icon="@android:drawable/ic_menu_add"     android:text="添加"/>

Android TabLayout选项卡如何使用android:icon 设置图标;

Android TabLayout选项卡如何使用Android:text 设置文本;

通过代码添加。使用 TabLayoutMediator()

        new TabLayoutMediator(binding.tab, binding.viewPager, new TabLayoutMediator.TabConfigurationStrategy() {            @Override            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {                //TODO 设置卡片的文本/图标                tab.setText(mTitles.get(position))                   .setIcon(mIcons.get(position));            }        }).attach();

其中 mTitles 和 mIcons 是存放 text 和 Icon 的list。效果如下:

Android TabLayout选项卡如何使用

可以看到 text 在英文状态下默认都是大写,这是因为在 TabLayout 的源码中默认设置属性 textAllCaps=true。所以可以在 TabLayout 中设置如下属性来改成小写。

app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"

Android TabLayout选项卡如何使用

演示效果的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:orientation="vertical"    tools:context=".MainActivity">    <com.google.android.material.tabs.TabLayout        android:id="@+id/tabs"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_margin="8dp">        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_add"            android:text="添加"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_delete"            android:text="删除"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_camera"            android:text="相机"/>    </com.google.android.material.tabs.TabLayout>    <com.google.android.material.tabs.TabLayout        android:id="@+id/tabs1"                android:layout_width="match_parent"        android:layout_height="wrap_content"        app:tabMode="scrollable"        android:layout_margin="8dp">        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_add"            android:text="添加"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_delete"            android:text="删除"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_camera"            android:text="相机"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_add"            android:text="添加"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_delete"            android:text="删除"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_camera"            android:text="相机"/>    </com.google.android.material.tabs.TabLayout>    <com.google.android.material.tabs.TabLayout        android:id="@+id/tabs2"                android:layout_width="match_parent"        android:layout_height="wrap_content"        app:tabIndicatorColor="@color/purple_700"        android:layout_margin="8dp">        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_add"            android:text="添加"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_delete"            android:text="删除"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_camera"            android:text="相机"/>    </com.google.android.material.tabs.TabLayout>    <com.google.android.material.tabs.TabLayout        android:layout_margin="8dp"        android:id="@+id/tabs3"                android:layout_width="match_parent"        android:layout_height="wrap_content">        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_add"            android:text="添加" />        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_call"            android:text="删除" />        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_camera"            android:text="菜单" />    </com.google.android.material.tabs.TabLayout>    <com.google.android.material.tabs.TabLayout        android:id="@+id/tabs4"        app:tabTextAppearance="@android:style/TextAppearance.Holo.Large"        android:layout_width="match_parent"        android:layout_height="wrap_content"        app:tabIndicatorHeight="0dp"        android:layout_margin="8dp">        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_add"            android:text="add"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_delete"            android:text="删除"/>        <com.google.android.material.tabs.TabItem            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:icon="@android:drawable/ic_menu_camera"            android:text="相机"/>    </com.google.android.material.tabs.TabLayout></LinearLayout>

以上就是关于“Android TabLayout选项卡如何使用”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注编程网精选频道。

--结束END--

本文标题: Android TabLayout选项卡如何使用

本文链接: https://www.lsjlt.com/news/355631.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android TabLayout选项卡如何使用
    这篇“Android TabLayout选项卡如何使用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Android...
    99+
    2023-07-05
  • Android使用TabLayout+Fragment实现顶部选项卡
    先看效果图:使用Tablayout,首先需要在项目中加入Design包dependencies { compile 'com.android.support:design:24.1.1' }...
    99+
    2023-05-31
    android tablayout fragment
  • TabLayout如何使用
    这篇文章给大家分享的是有关TabLayout如何使用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。TabLayout是design库提供的控件,可以方便的使用指示器,功能类似ViewPagerIndicator....
    99+
    2023-05-30
    android tablayout
  • 如何使用css3实现的tab选项卡
    这篇文章主要介绍“如何使用css3实现的tab选项卡”,在日常操作中,相信很多人在如何使用css3实现的tab选项卡问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何使用cs...
    99+
    2024-04-02
  • android选项卡TabHost功能怎么用
    本篇内容介绍了“android选项卡TabHost功能怎么用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!首先定义三个xml文件,分别为l1...
    99+
    2023-06-30
  • android选项卡TabHost功能用法详解
    本文实例为大家分享了android选项卡TabHost功能用法,供大家参考,具体内容如下 首先定义三个xml文件,分别为l1.xml,l2.xml,l3.xml,每个选项卡的标签页的...
    99+
    2024-04-02
  • AndroidTabLayout选项卡使用教程
    目录TabLayoutTabItem演示效果的xml TabLayout TabLayout 在开发中一般作为选项卡使用,常与 ViewPager2 和Fragment 结合起来使用...
    99+
    2023-05-14
    Android TabLayout Android TabLayout选项卡
  • Android TabLayout 自定义样式及使用详解
    目录基本使用XML静态设置TabItem联动ViewPager2动态设置TabItem1. Activity布局代码2. 创建三个Fragment给ViewPager2设置3. Fr...
    99+
    2024-04-02
  • js如何制作选项卡
    这篇文章主要介绍了js如何制作选项卡,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。具体内容如下<!doctype html&...
    99+
    2024-04-02
  • 如何使用CSS3实现选项卡切换功能
    这篇文章主要讲解了“如何使用CSS3实现选项卡切换功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何使用CSS3实现选项卡切换功能”吧!:target是...
    99+
    2024-04-02
  • vue选项卡如何切换
    今天小编给大家分享一下vue选项卡如何切换的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。在Vue.js中,使用选项卡切换可以...
    99+
    2023-07-05
  • vue如何实现选项卡
    这篇文章主要为大家展示了“vue如何实现选项卡”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“vue如何实现选项卡”这篇文章吧。具体内容如下实现步骤实现静态UI效果用传统的方式实现标签结构和样式基...
    99+
    2023-06-29
  • js中如何封装选项卡
    这篇文章将为大家详细讲解有关js中如何封装选项卡,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。这个插件对应的html的结构如下<div class=...
    99+
    2024-04-02
  • Android自定义选项卡切换效果
    本文实例为大家分享了Android自定义选项卡切换效果的具体代码,供大家参考,具体内容如下 一、实际使用的效果 二、自定义可切换的标题栏 1、布局 <?xml v...
    99+
    2024-04-02
  • 如何使用JavaScript检测空闲的浏览器选项卡
    今天就跟大家聊聊有关如何使用JavaScript检测空闲的浏览器选项卡,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。在某些情况下,当用户与我们的最终...
    99+
    2024-04-02
  • 如何使用HTML和CSS实现菜单选项卡布局
    在网页设计中,菜单选项卡布局是一种常见且实用的设计模式。通过使用HTML和CSS,我们可以轻松地实现一个具有功能完善的菜单选项卡布局。本文将介绍如何使用HTML和CSS创建一个菜单选项卡布局,并提供具体的代码示例。首先,我们需要使用HTML...
    99+
    2023-10-21
    CSS html 菜单选项卡布局
  • Android应用中怎么在底端显示选项卡
    这篇文章将为大家详细讲解有关Android应用中怎么在底端显示选项卡,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。layout 文件<&#63;xml version=&quo...
    99+
    2023-05-31
    android roi
  • 如何实现layui选项卡效果
    这篇文章将为大家详细讲解有关如何实现layui选项卡效果,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。具体内容如下<!DOCTYPE html> &...
    99+
    2024-04-02
  • vue如何实现选项卡组件
    这篇文章主要为大家展示了“vue如何实现选项卡组件”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“vue如何实现选项卡组件”这篇文章吧。具体内容如下主要功能:点击不同的选项,显示不同的内容html...
    99+
    2023-06-29
  • html如何实现二级选项卡
    这篇文章主要介绍了html如何实现二级选项卡,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。html实现二级选项卡的方法:首先打开写网页代码的软件,并新建一个html网页文件,...
    99+
    2023-06-06
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作