Tablayout 在 android 中显示标签周围的边框
Tablayout is showing borders around tabs in android
我升级了项目中的一些东西,即从 targetSdkVersion 27
升级到 targetSdkVersion 28
,升级了 gradle
之前一切正常,但在更新之后,我的 tabLayout 在选项卡周围显示了边框,如下图所示。我该如何解决这个问题。我搜索了这个问题,但没有看到任何相关问题
以防万一有人想看我的 tablayout xml
<android.support.design.widget.TabLayout
android:id="@+id/available_bundle_details_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_23sdp"
android:layout_marginEnd="@dimen/_23sdp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/lyt_available_bundle_detail_header"
app:tabBackground="@drawable/tab_selection_state"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabSelectedTextColor="#506694"
app:tabTextColor="#96506694"
/>
这是我用作 tabBackground
的 tab_selection_state
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- UNSELECTED TAB STATE -->
<item android:state_selected="false" android:state_pressed="false">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bottom indicator color for the UNSELECTED tab state -->
<item android:top="-5dp" android:left="-5dp" android:right="-5dp">
<shape android:shape="rectangle">
<stroke android:color="#96506694" android:width="1dp"/>
</shape>
</item>
</layer-list>
</item>
<!-- SELECTED TAB STATE -->
<item android:state_selected="true" android:state_pressed="true">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bottom indicator color for the SELECTED tab state -->
<item android:top="-5dp" android:left="-5dp" android:right="-5dp">
<shape android:shape="rectangle">
<stroke android:color="#506694" android:width="2dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
边框来自您的自定义可绘制对象,它在每个选项卡周围绘制一个矩形。很难说,为什么这只发生在 targetSDK=28 时,但您绝对可以通过重新访问您的自定义绘图来修复它。
尝试先移除矩形(或将颜色设置为透明),然后逐步尝试将其恢复,找出问题的确切原因。
我升级了项目中的一些东西,即从 targetSdkVersion 27
升级到 targetSdkVersion 28
,升级了 gradle
之前一切正常,但在更新之后,我的 tabLayout 在选项卡周围显示了边框,如下图所示。我该如何解决这个问题。我搜索了这个问题,但没有看到任何相关问题
以防万一有人想看我的 tablayout xml
<android.support.design.widget.TabLayout
android:id="@+id/available_bundle_details_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_23sdp"
android:layout_marginEnd="@dimen/_23sdp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/lyt_available_bundle_detail_header"
app:tabBackground="@drawable/tab_selection_state"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabSelectedTextColor="#506694"
app:tabTextColor="#96506694"
/>
这是我用作 tabBackground
tab_selection_state
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- UNSELECTED TAB STATE -->
<item android:state_selected="false" android:state_pressed="false">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bottom indicator color for the UNSELECTED tab state -->
<item android:top="-5dp" android:left="-5dp" android:right="-5dp">
<shape android:shape="rectangle">
<stroke android:color="#96506694" android:width="1dp"/>
</shape>
</item>
</layer-list>
</item>
<!-- SELECTED TAB STATE -->
<item android:state_selected="true" android:state_pressed="true">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bottom indicator color for the SELECTED tab state -->
<item android:top="-5dp" android:left="-5dp" android:right="-5dp">
<shape android:shape="rectangle">
<stroke android:color="#506694" android:width="2dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
边框来自您的自定义可绘制对象,它在每个选项卡周围绘制一个矩形。很难说,为什么这只发生在 targetSDK=28 时,但您绝对可以通过重新访问您的自定义绘图来修复它。
尝试先移除矩形(或将颜色设置为透明),然后逐步尝试将其恢复,找出问题的确切原因。