我目前正在创建一个应用程序并且出现了这个问题,我想让 TabLayout
透明。当我使用 RelativeLayout
TabLayout
覆盖内容时,当我使用 LinearLayout
TabLayout
背景不再透明。我该如何解决?
有一些图片和代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.news.MainActivity"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:background="#67000000"
app:tabTextColor="#ffffff"
android:layout_height="wrap_content"
app:tabSelectedTextColor="@color/colorAccent"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
最佳答案
为选项卡布局设置背景 android:background="@android:color/transparent"
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:hapticFeedbackEnabled="true"/>
或者你可以给自定义背景稍微透明的颜色
1) 90% - 90 e.g android:background="#90000000"
2) 80% - 90 e.g android:background="#80000000"
3) 70% - 70 e.g android:background="#70000000"
关于android - TabLayout 透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48776812/