要在Android的SlidingTabLayout中添加分割線,可以通過以下步驟實現:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="1dp"/>
<solid android:color="@android:color/darker_gray"/>
</shape>
TabLayout tabLayout = (TabLayout) getChildAt(0);
LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0);
for (int i = 0; i < tabStrip.getChildCount() - 1; i++) {
View tabView = tabStrip.getChildAt(i);
View divider = new View(getContext());
divider.setLayoutParams(new LinearLayout.LayoutParams(1, ViewGroup.LayoutParams.MATCH_PARENT));
divider.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.divider));
tabStrip.addView(divider);
}
<com.example.slidingtablayout.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
SlidingTabLayout slidingTabLayout = findViewById(R.id.sliding_tabs);
slidingTabLayout.setCustomTabView(R.layout.custom_tab, R.id.tab_text);
slidingTabLayout.setViewPager(viewPager);
通過以上步驟,你可以在Android的SlidingTabLayout中添加分割線。