Как сделать панель инструментов прозрачной, чей родитель Appbarlayout? - PullRequest
0 голосов
/ 05 июля 2018

Я пытался использовать стили и android: background: "@ null" / android: background: "@ color / transparent" внутри AppBarLayout, а также внутри панели инструментов V7, кажется, ничего не получается. Пробовал эти решения тоже:

1. Как сделать панель инструментов прозрачной?

<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>

Ответы [ 2 ]

0 голосов
/ 05 июля 2018

Попробуйте

    <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>
0 голосов
/ 05 июля 2018

В вашем AppBarLayout вам нужно установить

android: background = "@ null"

или

Android: фон = "@ андроид: цвет / прозрачный"

Я сейчас тестирую его, и он работает для меня

Дело в том, что если у вас есть макеты внутри вашей панели инструментов, как здесь, вам, вероятно, нужно установить их фоны также

 <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>
...