簡體   English   中英

具有自定義布局的透明導航抽屜 - Android

[英]Transparent Navigation Drawer with Custom Layout - Android

嘗試使用自定義設計制作完全透明的Navigation Drawer (嘗試僅包含自定義layout )。

  • Navigation Drawer中的透明背景和零elevation
  • 我不想要默認header或菜單items ,我想在其他 xml Layout中添加自定義設計,然后包含在里面

我怎樣才能做到這一點?

視頻示例: 在此處輸入圖像描述

如果你願意,讓你的Navigation Drawer完全Transparent ,然后使用它。 您可以在xml中進行自定義設計,然后將其includeNavigationView中。

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerlayout" <!-- we will use this layout id in java for hide elevation -->
android:orientation="vertical"
android:focusableInTouchMode="true"
>

<com.google.android.material.navigation.NavigationView
    android:background="@android:color/transparent" <!-- for transparent -->
    android:layout_width="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent">

    <include layout="@layout/custom_nav_drawer" />

</com.google.android.material.navigation.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>

在我們的Activity java類中用於隱藏drawer陰影/高程

DrawerLayout drawerLayout=findViewById(R.id.drawerlayout);
drawerLayout.setDrawerElevation(0f);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM