AppBarLayout高程隐藏工具栏 [英] AppBarLayout elevation hides toolbar

查看:73
本文介绍了AppBarLayout高程隐藏工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试禁用透明AppBarLayout/Toolbar下面的阴影.这是布局:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#000">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:background="@android:color/transparent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/imagePreviewToolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize" />

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

    <include layout="@layout/content_image_preview" />
</android.support.design.widget.CoordinatorLayout>

我已经尝试过

app:elevation="0dp"

getSupportActionBar().setElevation(0);

,但这使 UP箭头不可见.我还尝试删除AppBarLayout并仅使用工具栏,但是问题仍然存在.

but that makes the UP arrow invisible. I also tried to remove the AppBarLayout and use only the Toolbar, but the problem persists.

有人解决吗?

用以下代码替换AppBarLayout +工具栏组合:

Replacing the AppBarLayout + Toolbar combo with this code:

<android.support.v7.widget.Toolbar
    android:id="@+id/imagePreviewToolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@android:color/transparent"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:elevation="0dp"/>

部分解决了该问题.现在,仅当设备处于横向模式时,工具栏才变得不可见! Android Studio布局编辑器向我展示了两个方向的工具栏,所以我真的不知道问题可能出在哪里.

partially fixed the problem. Now the Toolbar becomes invisible only when the device is in landscape mode! The Android Studio Layout Editor shows me the Toolbar in both orientations just fine, so I don't really know what the problem could be..

推荐答案

经过几次尝试,我确实发现ToolBar在这种情况下应该是最后一个视图,否则,如果它是第一个,那么后面的视图将与它重叠将高度设置为match_parent,因此请在布局中尝试这种方式.

after some tries i did find that ToolBar should be the last view in this case else if it will be first then the view coming after it will overlap it as it has height set to match_parent so try this way in layout.

布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout  
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/imagePreviewToolbar" >

    <ImageView
        android:id="@+id/image_preview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/galacticos"
        android:contentDescription="abc"
        android:scaleType="fitCenter" />

    <LinearLayout
        android:id="@+id/actionBtns"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:padding="16dp" >

        <ImageButton
            android:id="@+id/setBackgroundBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@null"
            android:contentDescription="abc"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:id="@+id/downloadBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?selectableItemBackgroundBorderless"
            android:clickable="true"
            android:contentDescription="abc"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
</RelativeLayout>

<android.support.v7.widget.Toolbar
    android:id="@+id/imagePreviewToolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:fitsSystemWindows="true"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

别忘了全部初始化并将标题设置为false,以仅显示toolBar后退按钮:

And don't forget to initialize this all and set your title to false to only show the toolBar back button:

活动代码

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);

    Toolbar mToolBar = (Toolbar) findViewById(R.id.imagePreviewToolbar);
    setSupportActionBar(mToolBar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setHomeButtonEnabled(true);

}

图片

希望我能帮到你.

这篇关于AppBarLayout高程隐藏工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆