【问题标题】:Set elevation to View automatically the elevation of the Toolbar, how to change this?将海拔设置为自动查看工具栏的海拔,如何更改?
【发布时间】:2015-05-20 10:43:04
【问题描述】:

我正在使用默认情况下不会显示 ActionBar 的主题:

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

但是,我将其替换为 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>

在 OnCreate 中:

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

预期的结果是一个扁平的工具栏和线性布局下方的阴影,这正是 Android Studio 中的预览显示给我的:

然而在现实生活中,工具栏也已经生效了:

我只想将阴影放在另一个视图下方并保持我的工具栏平坦,如何实现这一点?这甚至可能吗?

【问题讨论】:

    标签: android xml android-appcompat android-actionbaractivity android-elevation


    【解决方案1】:

    不要将工具栏设置为支持操作栏。您仍然可以在工具栏上设置导航按钮、标题和膨胀菜单,但除非您在代码或活动布局中明确设置,否则不应应用海拔高度。

    话虽如此,请确保删除海拔不违反material design的原则。

    【讨论】:

      猜你喜欢
      • 2016-05-22
      • 1970-01-01
      • 1970-01-01
      • 2015-01-15
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      相关资源
      最近更新 更多