首页 文章

Tablayout显示了android中选项卡的边框

提问于
浏览
0

我在项目中升级了一些东西,即从 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"
            />

这是 tab_selection_state ,我正在使用 tabBackground

<?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>

1 回答

  • 0

    边框来自您的自定义drawables,它在每个选项卡周围绘制一个矩形 . 很难说,为什么这只发生在targetSDK = 28,但你可以通过重新访问自定义drawable来解决它 .

    尝试先删除矩形(或将颜色设置为透明),然后尝试逐步将其恢复,以找出究竟是什么导致了问题 .

相关问题