android - 工具栏默认没有阴影?

标签 android android-5.0-lollipop material-design android-toolbar

我正在使用支持库 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);

最佳答案

我最终为工具栏设置了自己的阴影,认为它可能对寻找它的人有所帮助:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="top"
              android:orientation="vertical">

    <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
                                       android:layout_width="match_parent"
                                       android:layout_height="wrap_content"
                                       android:background="@color/color_alizarin"
                                       android:titleTextAppearance="@color/White"
                                       app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

    <FrameLayout android:layout_width="match_parent"
                 android:layout_height="match_parent">

        <!-- **** Place Your Content Here **** -->

        <View android:layout_width="match_parent"
              android:layout_height="5dp"
              android:background="@drawable/toolbar_dropshadow"/>

    </FrameLayout>

</LinearLayout>

@drawable/toolbar_dropshadow:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
       android:shape="rectangle">

    <gradient android:startColor="@android:color/transparent"
              android:endColor="#88333333"
              android:angle="90"/>

</shape>

@color/color_alizarin

<color name="color_alizarin">#e74c3c</color>

enter image description here

关于android - 工具栏默认没有阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26575197/

相关文章:

android - AppCompat v7 工具栏 onOptionsItemSelected 未调用

java - 像 UBER 一样在 map 上动画/移动多辆汽车(标记)

angularjs - NgMaterial/Material Design 涟漪效应正在渗透边缘

android - 如何使用支持库实现波纹动画?

android - 推特用户界面控件

android - 滑动清除应用程序时广播接收器停止触发

java - 将 Arraylist<Arraylist<Integer>> 转换为 json

java - Android读取NFC标签数据

Android AppCompat-v21 与 Pure Material

android - 在 KitKat 上 Cardview 周围出现意外的白框,但在 Lollipop 上却没有