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

在我的活动-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_ALIZAIN"
                                       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/TOOLBLE_DROPSHOW:

<?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_ALIZAIN

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

在此处输入图像描述

Android相关问答推荐

如果在Kotlin中,如何避免使用过多?

在不增加父行宽度的情况下添加延迟行或可滚动行

LocalContext.current的问题(@Composable调用只能从@Composable函数的上下文发生)

我想使用代码自动重命名我的Android存储中的文件夹

我无法在底部导航栏中正确导航-Android底部导航视图

找不到com.android.tools.build:gradle:8.0

学习Kotlin问题.无法理解Modifier参数

如何在 Jetpack Compose LazyColumn 中将项目分组在一起,例如卡片

如何在每次显示可组合项时执行代码(并且只执行一次)

我可以从 Android 中的选定文本中获取周围的文本吗?

Jetpack Compose with Paging 3 发出太多网络请求

Jetpack Compose 部分或开放侧边框

react 从输入中找到路径'lib/arm64-v8a/libfbjni.so'的本机2个文件

GridLayout 和 GridView 有什么好用和区别

Gradle 构建错误:找不到 semver4j-0.16.4-nodeps.jar

不能在kotlin的lazycolumn中使用列表

Delphi 11:以编程方式查找 MSBuild 的正确工具版本

在jetpack compose中看不到圆角

如何在不使用 NestedScrollView 的情况下使用带有 CollapsingToolbar 的 ViewPager?

如何从构建的流对象中发出值