[英]how to add line above tabs android tablayout
需要幫忙
我已經搜索了我的要求,但沒有找到所以發布我自己的問題。
我需要在選項卡上方而不是下方顯示行,因為所有解決方案都是在選項卡文本下方添加行。
我應該使用自定義選項卡還是 android 支持這種情況而不進行自定義?
我看過的鏈接如下
沒有發布代碼,因為我想知道應該使用什么..你的建議會很有幫助..謝謝
嘗試此操作在res/drawable
文件夾中創建背景並設置app:tabBackground="@drawable/selector"
使您喜歡這個Tablayout
<android.support.design.widget.TabLayout
android:id="@+id/detail_tabs"
android:layout_width="match_parent"
app:tabSelectedTextColor="@color/colorPrimary"
app:tabIndicatorHeight="0dp"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabBackground="@drawable/selector" />
這里的selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:state_pressed="false">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="3dp" android:left="-5dp" android:right="-5dp" android:bottom="-5dp">
<shape android:shape="rectangle">
<solid android:color="@color/colorWhite"/>
<stroke android:color="@color/colorPrimary" android:width="2dp"/>
</shape>
</item>
</layer-list>
</item>
<item android:state_selected="true" android:state_pressed="true">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="3dp" android:left="-5dp" android:right="-5dp" android:bottom="-5dp">
<shape android:shape="rectangle">
<solid android:color="@color/colorWhite"/>
<stroke android:color="@color/colorPrimary" android:width="2dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
希望它能正常工作,然后添加評論。
app:tabIndicatorGravity="top"
現在用這個在頂部顯示指標非常簡單。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.