【问题标题】:DrawerLayout is not showing on my preview window.How to fix this?DrawerLayout 没有显示在我的预览窗口中。如何解决这个问题?
【发布时间】:2020-02-07 08:42:15
【问题描述】:

我在我的应用中添加了一个抽屉布局。但它没有被显示。当我在模拟器上运行应用程序时,它会自行打开然后关闭。 here is the screenshot of the preview window

这是布局文件:-

?xml version="1.0" encoding="utf-8"?>
<androidx.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/content_frame"/>
    <ListView
        android:id="@+id/drawer"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:text="Hello World!"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#ffffff"/>


</androidx.support.v4.widget.DrawerLayout>

这里是 buil.gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.bitsandpizzas"
        minSdkVersion 17
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

【问题讨论】:

    标签: android drawerlayout


    【解决方案1】:

    您忘记添加 导航 没有导航抽屉不起作用

    或者你可以从这里举个例子,它对我有用https://www.journaldev.com/9958/android-navigation-drawer-example-tutorial

    【讨论】:

    • 我必须在哪里添加导航?
    • 我把链接发给你,你可以检查一下。它为我工作
    • 有什么方法可以把你的代码截图发给我吗?
    猜你喜欢
    • 2020-08-04
    • 2023-03-03
    • 2019-02-02
    • 2022-06-14
    • 2021-11-21
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多