TabLayout添加分割线

来源:互联网 发布:我的世界pe服务器端口 编辑:程序博客网 时间:2024/06/06 08:23

为TabLayout添加分割线,显示的效果如下(红框内部分):
分割线

首先添加个竖线xml名为layout_divider_vertical:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">    <solid android:color="#80c0c0c0"/>    <size android:width="1dp"/></shape>

在代码中引用:

 LinearLayout linearLayout = (LinearLayout) mTabLayout.getChildAt(0);        linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);        linearLayout.setDividerDrawable(ContextCompat.getDrawable(this,                R.drawable.layout_divider_vertical));

mTabLayout就是要添加分割线的控件

4 0