Tablayout指示器不可见

发布于 2025-02-01 20:42:40 字数 2136 浏览 2 评论 0原文

我想将自定义形状作为tablayout指示器。它假设围绕tabitem图标(例如椭圆形button)。但是,由于我设置它,由于某种原因,只有图标颜色正在变化,我根本看不到指示器。

tableAut:

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:paddingTop="@dimen/padding_small"
        android:paddingBottom="@dimen/padding_medium"
        app:tabIndicatorGravity="center"
        app:tabIconTint="@color/tab_icon_tint"
        app:tabIndicator="@drawable/tab_indicator"
        app:tabRippleColor="@null">

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:icon="@drawable/tab_account_icon"/>

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </com.google.android.material.tabs.TabLayout>

tab_indicator.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <solid android:color="@color/tab_selected" />
</shape>

我尝试更改tab_indicator.xml初始化,如果它有所不同(也许需要层列表作为输入),但结果相同。

<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:gravity="center">

    <shape
        android:shape="oval" >
        <solid android:color="@color/tab_selected" />
    </shape>

</item>

</layer-list>

想要实现此设计(指示器是tabicon周围的圆圈,在选择选项卡时应移动到下一个选项卡):

“在此处输入图像说明”

I want to make custom shape as TabLayout indicator. It suppose to be circle around TabItem icon (like oval Button). But as I set it, for some reason, only icon color is changing and I cant see indicator at all.

TabLayout:

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:paddingTop="@dimen/padding_small"
        android:paddingBottom="@dimen/padding_medium"
        app:tabIndicatorGravity="center"
        app:tabIconTint="@color/tab_icon_tint"
        app:tabIndicator="@drawable/tab_indicator"
        app:tabRippleColor="@null">

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:icon="@drawable/tab_account_icon"/>

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </com.google.android.material.tabs.TabLayout>

tab_indicator.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <solid android:color="@color/tab_selected" />
</shape>

I tried to change tab_indicator.xml initialization if it makes some difference (maybe it needs layer-list as input) but same result.

<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:gravity="center">

    <shape
        android:shape="oval" >
        <solid android:color="@color/tab_selected" />
    </shape>

</item>

</layer-list>

Want to achieve this design(indicator is circle around tabIcon and should move while selecting tab to next tab):

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文