【问题标题】:Android DrawerLayout and NavigationView not fully expandedAndroid DrawerLayout 和 NavigationView 未完全展开
【发布时间】:2020-02-09 03:24:35
【问题描述】:

您好,我已经构建了一个带有 NavigationView 和工具栏的 DrawerLayout。问题是 NavigationView 没有像图片中那样完全展开。我尝试使用 android:fitsSystemWindows = true 和 false 但没有奏效。

这是我在布局文件中的代码。

    <?xml version="1.0" encoding="utf-8"?>
<layout 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"
    tools:context=".view.MainActivity">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <FrameLayout
            android:id="@+id/frame_sceneform_fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <fragment
                android:id="@+id/sceneform_fragment"
                android:name="com.google.ar.sceneform.ux.ArFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </FrameLayout>


        <FrameLayout
            android:id="@+id/frame_menu_nav_host"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="100dp"
            android:background="#FFFFFF"
            android:visibility="invisible"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
            <androidx.drawerlayout.widget.DrawerLayout
                android:id="@+id/drawer_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">
                    <androidx.appcompat.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        />

                    <fragment
                        android:id="@+id/fragment_menu_nav_host"
             android:name="androidx.navigation.fragment.NavHostFragment"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        app:defaultNavHost="true"
                        app:navGraph="@navigation/menu_navigation" />
                </LinearLayout>
                <com.google.android.material.navigation.NavigationView
                    android:id="@+id/nav_view"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="start"
                    app:menu="@menu/hamburger_menu"/>
            </androidx.drawerlayout.widget.DrawerLayout>

        </FrameLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

我想删除状态栏通常所在的灰色区域以及底部为移动设备上的操作按钮指定的灰色区域。这可能吗?还是我必须进行定制设计?

【问题讨论】:

  • 你能发布整个 xml 文件吗?
  • 现已添加。

标签: android android-layout navigation-drawer drawerlayout navigationview


【解决方案1】:

像这样将新样式放入您的 style.xml 文件夹中;

    <style name="AppTheme.NoActionBar" >
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

并在你的清单文件中定义它;

<activity android:name=".MainActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    相关资源
    最近更新 更多