【安卓开发】TabLayout的使用

简介: 【安卓开发】TabLayout的使用

用途

作为标签栏,和V i e w P a g e r页面实现联合滑动。

添加依赖

implementation 'com.android.support:design:26.1.0'

编写xml文件

app:tabMode=“fixed” 固定标题栏;scrollable指标题栏可滑动

tabGravity="center"居中显示,fill 占满全屏

tabIndicatorColor 导航条中标题被选中时下划线的颜色

tabSelectedTextColor导航条中标题被选中时标题栏的颜色

<com.google.android.material.tabs.TabLayout
            android:id="@+id/record_tabs"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            app:tabGravity="center"
            app:tabMode="fixed"
            app:tabTextColor="#7D7D7D"
            app:tabSelectedTextColor="@color/black"
            app:tabIndicatorColor="@color/black"/>
<androidx.viewpager.widget.ViewPager
        android:id="@+id/record_vp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

绑定ViewPager和TabLayout

TabLayout tableLayout;
ViewPager viewPager;
tableLayout=findViewById(R.id.record_tabs);//查找控件
        viewPager=findViewById(R.id.record_vp);
tableLayout.setupWithViewPager(viewPager);//绑定
目录
相关文章
|
Android开发
【安卓开发】Android实现画板
【安卓开发】Android实现画板
101 0
|
Java Android开发
【安卓开发】Android中自定义软键盘的使用
【安卓开发】Android中自定义软键盘的使用
400 0
【安卓开发】Android中自定义软键盘的使用
|
XML Android开发 数据格式
Android RecyclerView从入门到玩坏
目录 前言 基础使用 分隔线 点击监听 搭配CardView 更丰富的条目 增删条目 快速添加视图 让RecyclerView支持复杂视图 最后 前言 RecyclerView在Android界面开发当中是很重要的, 那掌握它也是很必要的.
1218 0

热门文章

最新文章