简体   繁体   English

将标高设置为“自动查看工具栏的标高”,如何更改?

[英]Set elevation to View automatically the elevation of the Toolbar, how to change this?

I'm using a theme that will not show the ActionBar by default: 我使用的主题默认情况下不会显示ActionBar:

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="windowActionBar">false</item>
    <item name="android:textColorPrimary">#FFFFFF</item>
</style>

However, I'm replacing it with Toolbar in xml: 但是,我用xml中的工具栏替换了它:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    ... >

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="@color/MainColor"
        android:elevation="@dimen/default_elevation"
        android:orientation="vertical">

    </LinearLayout>

</LinearLayout>

in OnCreate: 在OnCreate中:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_VenueDetail);
setSupportActionBar(toolbar);

The expected result is a flat Toolbar and a shadow below the LinearLayout, which is exactly what preview in Android Studio shows me: 预期的结果是一个平坦的工具栏和LinearLayout下的阴影,这正是Android Studio中的预览向我显示的内容:

在Nexus 4上预览

However in real life, the Toolbar has also taken effect: 但是,在现实生活中,工具栏也已生效:

Nexus 5的屏幕截图

I want to just put the shadow below another View and keep my Toolbar flat, how to achieve this? 我只想将阴影放在另一个视图下面,并使我的工具栏保持平整,如何实现呢? Is this even possible? 这有可能吗?

Do not set the toolbar as a support actionbar. 不要将工具栏设置为支持操作栏。 You can still set navigation button, title and inflate menu on the toolbar but the elevation shouldn't be applied unless you set it explicitly in code or in the activity layout. 您仍然可以在工具栏上设置导航按钮,标题和充气菜单,但是除非您在代码或活动布局中明确设置了高程,否则不应应用高程。

Having said that, make sure that the removing the elevation is not against the principles of material design . 话虽如此,请确保移除标高不违反材料设计原则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM