【问题标题】:How to make toolbar transparent who's parent is Appbarlayout?如何使工具栏透明谁的父母是Appbarlayout?
【发布时间】:2018-07-05 21:17:22
【问题描述】:

我尝试在 AppBarLayout 以及 V7 工具栏中使用样式和 android:background:"@null" / android:background:"@color/transparent" 似乎没有任何锻炼。 也尝试过这些解决方案:

1.How to make Toolbar transparent?

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

<include
    layout="@layout/main_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/green"
    android:fitsSystemWindows="true"
    android:paddingTop="25dp"
    app:itemTextColor="#c92e30">
  </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

我已包含此布局

  <android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context="com.g5web.aastha.activities.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        app:contentInsetStartWithNavigation="0dp">

        <LinearLayout
            android:id="@+id/toolbar1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="15dp"
                android:gravity="center">

                <ImageView
                    android:id="@+id/toolbar_title_image"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/signin"
                    android:visibility="gone" />

                <ImageView
                    android:id="@+id/ivLogo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:visibility="gone" />

                <TextView
                    android:id="@+id/toolbar_title_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:gravity="center"
                    android:textColor="@color/blue"
                    android:visibility="gone" />

            </RelativeLayout>

        </LinearLayout>

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

<include layout="@layout/frame_container" />
<!--</LinearLayout>-->

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

【问题讨论】:

    标签: android toolbar android-appbarlayout navigation-drawer


    【解决方案1】:

    在你的 AppBarLayout 上你需要设置

    android:background="@null"

    android:background="@android:color/transparent"

    我现在正在测试它,它对我有用

    问题是,如果您的工具栏中有像这里这样的布局,您可能还需要设置它们的背景

     <LinearLayout
                android:id="@+id/toolbar1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
    
    
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="15dp"
                    android:gravity="center">
    
                    <ImageView
                        android:id="@+id/toolbar_title_image"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/signin"
                        android:visibility="gone" />
    
                    <ImageView
                        android:id="@+id/ivLogo"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:visibility="gone" />
    
                    <TextView
                        android:id="@+id/toolbar_title_title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:gravity="center"
                        android:textColor="@color/blue"
                        android:visibility="gone" />
    
                </RelativeLayout>
    
            </LinearLayout>
    

    【讨论】:

    • 我已经尝试过 android:background:"@null" / android:background:"@color/transparent" 这不起作用。我什至尝试在工具栏下的布局中设置相同的设置,但也不起作用。
    【解决方案2】:

    试试这个

        <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:elevation="0dp">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/transparent"
            android:theme="@style/AppTheme.PopupOverlay"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:title="@string/app_name"
            app:titleTextColor="@android:color/white" />
    
    </android.support.design.widget.AppBarLayout>
    

    【讨论】:

    • 嗨。 Apptheme.PopupOverlay 需要在样式中应用任何特定属性吗?因为您的解决方案也不起作用。
    • @ Shubham Vala @JoaquinAlvarez 我刚刚尝试将 Toolbar 放入 FrameLayout 并删除 AppBarLayout 现在它似乎可以工作了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-18
    • 2018-06-20
    相关资源
    最近更新 更多