Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在应用程序启动后删除AppBar阴影_Android_Android Appbarlayout - Fatal编程技术网

Android 如何在应用程序启动后删除AppBar阴影

Android 如何在应用程序启动后删除AppBar阴影,android,android-appbarlayout,Android,Android Appbarlayout,我有抽屉布局,我需要删除特定页面(片段)的AppBar阴影。 为此,我使用此代码 fun setToolbarShadow(dropShadow: Boolean) { if (dropShadow) { ViewCompat.setElevation(appBar, Utils.dp2px(4, resources)) } else { ViewCompat.setElevation(appBar, 0f) } } 它比第一个片段更适用

我有抽屉布局,我需要删除特定页面(片段)的AppBar阴影。 为此,我使用此代码

fun setToolbarShadow(dropShadow: Boolean) {
    if (dropShadow) {
        ViewCompat.setElevation(appBar, Utils.dp2px(4, resources))
    } else {
        ViewCompat.setElevation(appBar, 0f)
    }
}
它比第一个片段更适用于其他片段。 我试着把它放在活动的
onCreate
onStart
onCreateView
onViewCreated
的片段中,但没有任何效果。 创建活动和片段后如何正确设置它

编辑: 我制作了一个简单的hello world应用程序,其中有一个活动可以尝试,下面是代码:

活动\u main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="cz.svobodaf.myapplication.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

    <FrameLayout
        android:id="@+id/top_nav_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" />

</android.support.design.widget.AppBarLayout>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
这在启动后也不起作用,但当我锁定设备并再次解锁时,
onResume
被调用,它会突然起作用。
我需要知道ehere在应用程序启动后将代码设置为高程。

我通过将AppBar outlines设置为null找到了解决方案

appBar.outlineProvider = null

但我不明白为什么海拔不起作用。似乎在调用所有启动方法之后设置了提升-。-

如果此方法工作正常,则调用时会出现一些问题。因此,在这个方法中添加调用代码。我编辑了我的问题以添加所有相关信息。
appBar.outlineProvider = null