首页 > 解决方案 > 如何使工具栏边缘透明?

问题描述

我有一个位于选项卡布局顶部的工具栏。这两个都将使用相同的颜色渐变作为背景。我试图摆脱工具栏或选项卡布局上的边缘,以便它们融合在一起,因为现在它们之间有一条黑线。有什么方法可以使它们之间的这条线透明吗?我以前在 Xcode 上做过。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/menu_gradient"
    android:id="@+id/content">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@drawable/transparent"
        android:id="@+id/main_toolbar"
        android:elevation="4dp"
        app:titleTextColor="#ffffff"
        tools:ignore="MissingConstraints"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@mipmap/logos_round" />

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:background="@drawable/menu_gradient"
        android:layout_height="wrap_content">

        <android.support.design.widget.TabLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:id="@+id/tabs"
            android:elevation="5dp"
            android:background="@drawable/transparent"
            app:tabTextColor="@color/colorPrimary"
            app:tabTextAppearance="@style/customTabText"
            app:tabMode="fixed">
        </android.support.design.widget.TabLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">
    </android.support.v4.view.ViewPager>
</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:menu="@menu/activity_main_drawer"
    android:background="@color/colorPrimary"/>
</android.support.v4.widget.DrawerLayout>

标签: javaandroidandroid-layout

解决方案


包括ToolBar里面的AppBarLayout,上面TabLayout如下:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:background="@drawable/menu_gradient"
    android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
           android:layout_width="match_parent"
           android:layout_height="?attr/actionBarSize"
           android:background="@drawable/transparent"
           android:id="@+id/main_toolbar"
           android:elevation="4dp"
           app:titleTextColor="#ffffff"
           tools:ignore="MissingConstraints"
           android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
           app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@mipmap/logos_round" />

    </android.support.v7.widget.Toolbar>


    <android.support.design.widget.TabLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/tabs"
        android:elevation="5dp"
        android:background="@drawable/transparent"
        app:tabTextColor="@color/colorPrimary"
        app:tabTextAppearance="@style/customTabText"
        app:tabMode="fixed">
    </android.support.design.widget.TabLayout>

</android.support.design.widget.AppBarLayout>

推荐阅读