【问题标题】:Toolbar doesnt cast shadow in my app on my device (Android studio)工具栏不会在我的设备上的应用程序中投下阴影(Android 工作室)
【发布时间】:2016-02-27 18:24:57
【问题描述】:

我有一个工具栏布局和 mainlayout 。 在我的主布局中,我包含了我的工具栏布局:

工具栏布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/PrimaryButtonsAndHeadscolor"
android:titleTextAppearance="@color/ColorPrimaryDark"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:elevation="8dp">
</android.support.v7.widget.Toolbar>

我的主要布局(带有工具栏的部分):

  <LinearLayout


    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainScreen"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        >

      >
    <include
    android:id="@+id/tool_bar"
    layout="@layout/tool_bar"
    ></include>
    </LinearLayout>

在“预览”屏幕上的 andorid studio 上,我的工具栏投下了阴影,但是当我在我的设备上运行它时却没有。 我知道海拔属性适用于在 api 21+ 上运行的设备,我使用的是 lgg-4 api22,因此它应该在工具栏下方投射阴影(我还在其他应用程序中看到工具栏下方的阴影)。 我在做什么?

谢谢!

【问题讨论】:

  • 不工作:/,现在预览中也没有阴影
  • Android 5.1,我应该验证什么?
  • 你可以尝试设置requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
  • 我刚刚将此布局插入到一个新的空白项目中,它工作得很好,高程阴影显示。在 6.0.1 上测试
  • 所以我的设备有问题?

标签: java android toolbar shadow elevation


【解决方案1】:

好的,所以最后我发现了问题:我的错误是我将工具栏放在内部 LinearLayout 中(这就是在设备上运行时以某种方式取消了提升效果)。

以前的布局:

    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainScreen"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        >
            >
            <include
                android:id="@+id/tool_bar"
                layout="@layout/tool_bar"
                ></include>
    </LinearLayout>

新布局:

    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainScreen"
    android:orientation="vertical">

            >
            <include
                android:id="@+id/tool_bar"
                layout="@layout/tool_bar"
                ></include>

它有效,我的工具栏上有一个阴影!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-03
    • 2023-03-27
    • 2016-03-08
    • 2015-09-15
    • 2021-02-13
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多