Android:TabLayout 当中的tabItem点击事件

本篇文章只含有tabItem的点击事件,其他没有滑动等内容,赶时间及时略过该文

在这里插入图片描述

布局

    <com.google.android.material.tabs.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabRippleColor = "@android:color/transparent"
        android:id="@+id/tab_tablayout"
        >

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tab_event_details"
            android:text="事件信息" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tab_deal_details"
            android:text="处理信息" />

    </com.google.android.material.tabs.TabLayout>

代码

        tab_tablayout =  (TabLayout) findViewById(R.id.tab_tablayout);
        tab_tablayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {

              //  tab.getPosition()  返回数字,从0开始
               // tab.getText()  返回字符串类型,从0开始
                if (tab.getPosition()==0){
                    sv_eventdetail.setVisibility(View.VISIBLE);//这个是用来显示隐藏的布局用的
                }
            }
            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }
            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

还要注意一下定义

private TabLayout tab_tablayout;
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="30dp" tools:context=".LoginActivity"> <com.google.android.material.tabs.TabLayout android:id="@+id/tablayout" app:tabIndicatorColor="#00B7FF" app:tabIndicatorFullWidth="false" android:paddingTop="80dp" android:layout_width="300dp" android:layout_height="wrap_content"> <com.google.android.material.tabs.TabItem android:id="@+id/tab1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="验证码登录" /> <com.google.android.material.tabs.TabItem android:id="@+id/tab2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码登录" /> </com.google.android.material.tabs.TabLayout> <FrameLayout android:id="@+id/fl" android:layout_above="@+id/textView3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/tablayout"> </FrameLayout> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/radioButton" android:paddingBottom="20dp" android:layout_centerHorizontal="true" android:textColor="#00B7FF" android:drawableStart="@drawable/baseline_apartment_24" android:text=" 用学校统一身份登录" /> <RadioButton android:id="@+id/radioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:textColor="#00B7FF" android:text="我已阅读并同意《用户协议》和《隐私政策》" /> </RelativeLayout>分析这段代码运用了哪些控件
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Wenlong Yang

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

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

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

打赏作者

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

抵扣说明:

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

余额充值