如何解决没有来自 TabLayout 的 alpha 值的 TabItem
我正在使用带有一些特定 alpha 值的 TabLayout,并且选项卡项被设置为有一个图标。但是,我不希望将此 alpha 值应用于图标,而只是应用于 TabLayout 背景。
<com.google.android.material.tabs.TabLayout
android:id="@+id/id"
style="@style/style"
android:background="@color/someColor"
android:alpha="0.2">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/icon1" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/icon2" />
</com.google.android.material.tabs.TabLayout>
图标也以一些透明度显示,但我希望它以其原始颜色显示。 我试图为每个 TabItem 添加 alpha 属性,但似乎被忽略了。我怎样才能让它工作?
解决方法
你必须使用半透明的 drawable 作为 TabLayout 的背景色。创建一个带有颜色(包括 alpha)的 drawable。
tab_bg.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#5000ddfa" />
</shape>
在您的 TabLayout 中使用它,并删除 android:alpha
:
<com.google.android.material.tabs.TabLayout
android:id="@+id/id"
style="@style/style"
android:background="drawable/tab_bg">
...
</com.google.android.material.tabs.TabLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。