简体   繁体   English

工具栏不会在设备上的应用中投射阴影(Android Studio)

[英]Toolbar doesnt cast shadow in my app on my device (Android studio)

I have a toolbar layout and mainlayout . 我有一个工具栏布局和mainlayout。 In my mainlayout I include my toolbar layout : 在主布局中,我包括工具栏布局:

Toolbar layout : 工具栏布局:

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

My main layout (the part with the 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>

On andorid studio at the "preview" screen my tool bar cast a shadow , but when I run it on my device it doesn't. 在“预览”屏幕上的andorid studio上,我的工具栏投射了阴影,但是当我在设备上运行它时却没有。 I know that elevation attribute is suitable for device running on api 21+ , I am using lgg-4 api22 so it should cast shadow beneath the toolbar (I also see shadow beneath the toolbar in other apps ). 我知道海拔属性适合在api 21+上运行的设备,我使用的是lgg-4 api22,因此它应该在工具栏下方投射阴影(我也可以在其他应用程序的工具栏下方看到阴影)。 What I am doing worng ? 我在做什么?

thanks ! 谢谢 !

Okay , so finally I found the problem : my mistake was the fact I put my toolbar in an internal LinearLayout (and thats somehow Cancelling the elevation effect when running on device). 好的,所以最后我找到了问题:我的错误是我将工具栏放在内部LinearLayout中(这就是在设备上运行时取消高程效果的事实)。

Previous Layout : 以前的布局:

    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>

New layout : 新版面 :

    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>

It works,there is a shadow on my toolbar ! 它有效,我的工具栏上有阴影!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM