【发布时间】:2014-12-21 21:38:33
【问题描述】:
我正在使用支持库 v21 中的新工具栏更新我的应用程序。我的问题是,如果我不设置“海拔”属性,工具栏不会投射任何阴影。这是正常行为还是我做错了什么?
我的代码是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<FrameLayout
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
.
.
.
在我的 Activity - OnCreate 方法中:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
【问题讨论】:
-
您是否在运行 Lollipop 的设备上看到此内容?
-
在运行 Lollipop 的设备上由于海拔属性而显示阴影,但在 KitKat 或更旧版本上不显示。这就是文档所述的海拔属性的预期行为,但我期望在默认情况下没有海拔属性,阴影会像每个版本的操作栏一样投射。
-
我在这里发布了一个可能的解决方案:stackoverflow.com/a/26759202/553905
-
使用 /values 文件夹和 styles.xml 根据操作系统版本应用正确的影子代码(见下文)。
标签: android android-5.0-lollipop material-design android-toolbar