android d弹框顶部突出,TextView + Tablayout实现顶部菜单栏效果

实现的效果如下图所示:

1560424356x3703728804.png 其中,左侧全部按钮控件为TextView,右侧标签为XTabLayout控件。 1.布局文件

android:id="@+id/cl_tablayout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:layout_constraintTop_toBottomOf="@+id/tl_game_classfied"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

android:background="@color/statusbar"

app:layout_scrollFlags="scroll|enterAlways"

>

android:id="@+id/tv_all"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="16sp"

android:text="全部"

android:textColor="@color/green"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintRight_toLeftOf="@+id/tl_show"

android:padding="5dp"

android:layout_marginLeft="5dp"

android:layout_marginRight="5dp"

/>

android:id="@+id/tl_show"

android:layout_width="0dp"

app:layout_constraintLeft_toRightOf="@+id/tv_all"

app:layout_constraintRight_toRightOf="parent"

android:layout_height="wrap_content"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintBottom_toBottomOf="parent"

app:xTabMode="scrollable"

app:xTabIndicatorHeight="0dp"

app:xTabIndicatorColor="@color/statusbar"

app:xTabTextColor="@color/white"

app:xTabSelectedTextColor="@color/green"

android:textAlignment="center"

>

2.在activity中进行设置

private int cnt = 0; //防止初始化时将TextView的颜色设置为白色

...

...

tl_show.addOnTabSelectedListener(new XTabLayout.OnTabSelectedListener() {

@Override

public void onTabSelected(XTabLayout.Tab tab) {

tl_show.setTabTextColors(Color.WHITE, Color.parseColor("#54ba3d"));

if (cnt != 0) {

tv_all.setTextColor(Color.WHITE);

} else {

cnt = 1;

}

}

@Override

public void onTabUnselected(XTabLayout.Tab tab) {

}

@Override

public void onTabReselected(XTabLayout.Tab tab) {

tl_show.setTabTextColors(Color.WHITE, Color.parseColor("#54ba3d"));

if (cnt != 0) {

tv_all.setTextColor(Color.WHITE);

} else {

cnt = 1;

}

}

});

tv_all.setTextColor(Color.parseColor("#54ba3d"));

...

tl_show.setTabTextColors(Color.WHITE, Color.WHITE);

tv_all.setOnClickListener(v -> {

tl_show.getTabAt(0).select();

tv_all.setTextColor(Color.parseColor("#54ba3d"));

tl_show.setTabTextColors(Color.WHITE, Color.WHITE);

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值