I have a working DrawerLayout
with several elements within it. All elements inside the drawer are located within a RelativeLayout
. The weird part is whenever the drawer is opened, the EditText
receives focus automatically, and never looses it. I tried adding android:clickable="true"
attribute to the parent element (which is the RelativeLayout
) to trick the focus issue but it does not help. Any ideas what is causing this behavior?
<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">
<!-- The first child in the layout is for the main Activity UI-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#ffffffff">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listViewChat"
android:layout_centerHorizontal="true"
android:choiceMode="multipleChoice" />
</RelativeLayout>
<!-- Side navigation drawer UI -->
<RelativeLayout
android:id="@+id/drawerContainer"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="@drawable/splash_background_blur"
android:clickable="true">
<!--this custom view serves as a dimmer for the drawer -->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#73000000"
android:id="@+id/view1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<!--this edit text receives focus automatically on drawer open -->
<!--and never looses focus as long as the drawer is opened -->
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editTextUserName"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp"
android:cursorVisible="false"
android:textColor="#FFF"
android:textSize="20sp"
android:background="@null"
android:maxLength="15"
android:inputType="textNoSuggestions"/>
<Button
android:layout_width="220dp"
android:layout_height="35dp"
android:text="@string/buttonSelectPhoto"
android:id="@+id/buttonTakePhoto"
android:background="@drawable/splash_button"
android:textColor="#FFF"
android:layout_marginTop="200dp"
android:layout_marginLeft="25dp"
android:layout_marginStart="25dp"/>
<ListView
android:id="@+id/navList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
EDIT : Just to sharpen things a bit: I test the app on the emulator, and when I reveal the drawer without touching a thing, the editText
gains focus (meaning I swipe to the right, drawer is visible, I type on the keyboard and the text is seen inside the editText
without actually clicking it)