Wenn ich meine Navigationsleiste in einer Android App, die ich erstellt habe, öffne, kann ich immer noch auf Listenelemente in meinem Hauptlayout klicken (Das Inhaltslayout). Ich meine, ich bin tatsächlich in der Lage, auf einen ListView
Artikel durch meine Navigationsschublade zu klicken. Ich habe noch keine anklickbaren Elemente in der Navigationsleiste, aber ich habe es in einen richtigen FrameLayout
mit einem weißen Hintergrund eingefügt. Der Inhalt der Schublade entwerfe ich in einem Fragment. Hier ist mein Code:Android: Kann durch die Nav-Schublade klicken? AppCompat v7: r21
activity_home.xml (MainActivity)
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
tools:context=".HomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar_home"
layout="@layout/my_awesome_toolbar" />
<FrameLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:id="@+id/fab_addContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="@dimen/view_margin_large"
android:layout_marginEnd="@dimen/view_margin_large"
android:layout_marginRight="@dimen/view_margin_large"
android:background="@drawable/fab_button"
android:contentDescription="@string/fab_contDesc"
android:padding="@dimen/view_margin_large"
android:src="@drawable/ic_add_white_24dp" />
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/drawer_frame"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
android:clickable="true" />
</android.support.v4.widget.DrawerLayout>
fragment_drawer.xml (DrawerFragment gehen in die @+id/drawer_frame
)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="144dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/material_design_wallpaper" />
<ImageView
android:id="@+id/iv_userThumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="16dp"
android:background="@drawable/display_pic_thumbnail"
android:contentDescription="@string/contact_thumbnail" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/view_margin_xx_large"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/shadow" />
<TextView
android:id="@+id/tv_userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/tv_userEmail"
android:layout_alignLeft="@+id/tv_userEmail"
android:layout_alignStart="@+id/tv_userEmail"
android:layout_marginBottom="@dimen/view_margin_small"
android:text="Siddhant Chavlekar"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_userEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="@dimen/view_margin_large"
android:layout_marginLeft="@dimen/view_margin_large"
android:layout_marginStart="@dimen/view_margin_large"
android:text="[email protected]"
android:textColor="@android:color/white" />
</RelativeLayout>
</LinearLayout>
Warum ist das passiert? Ich verwende die AppCompat v7:r21
-Bibliothek, um Abwärtskompatibilität für meine Lollipop (Material Design) -Apps bereitzustellen.
Ich hatte diese Art von Erfahrung vor der Veröffentlichung von Android 21, ich habe es gelöst, indem ich diese Zeile zu meinen Layouts innerhalb der DrawerLayout 'android hinzufügen: clickable =" true "' – k0sh
@ k0sh so füge ich es allen Layouts in meinem 'DrawerLayout' oder nur der Schublade hinzu? – SynerFlow
Nein, du fügst es zu den Layouts hinzu, die innerhalb des Drawerlayouts liegen, außer dem Layout, das die Schublade childs hält – k0sh