【问题标题】:Remove toolbar elevation for specific fragment删除特定片段的工具栏高度
【发布时间】:2016-12-20 08:44:33
【问题描述】:

如何将 Elevation 设置为 0 或为我的 NavigationDrawer 的特定 Fragment 禁用它?以编程方式或主题?

toolbar.setElevation(0) 似乎不起作用。

我的onNavigationItemSelected 不起作用,海拔不会改变:

if (item.getItemId() == R.id.drawer_menu_account) {
    if (getSupportActionBar() != null) {
        getSupportActionBar().setElevation(0);
    }
} else {
    if (getSupportActionBar() != null) {
        getSupportActionBar().setElevation(8);
    }
}

还有我的带有工具栏的协调器布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?attr/actionBarSize" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_add_24dp" />

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



已解决 - 感谢 Amir!在我的 onNavigationItemSelected

中使用它
if (android.os.Build.VERSION.SDK_INT >= 21) {
    if (item.getItemId() == R.id.drawer_menu_account) {
         appBar.setElevation(0);
    } else {
         appBar.setElevation(8);
    }
}

【问题讨论】:

  • 我认为您应该将 Appbar 高度设置为零。
  • 我已尝试查看我的编辑。实际上它不起作用..
  • 你能通过你的 xml 吗?
  • 查看我的编辑,使用工具栏添加我的 CoordinatorLayout
  • 为您的 Appbar 设置 ID 并为您的 appBar 而不是 Toolbar 设置高度

标签: android toolbar elevation


【解决方案1】:

要删除工具栏中的阴影,请使用

app:elevation="0" 在 AppBarLayout xml 或

在java中使用mAppBarLayout.setTargetElevation(0)

它对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    相关资源
    最近更新 更多