Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable auto focus on edit text

I have an edit text:

   <LinearLayout android:id="@+id/linearLayout7" android:layout_width="match_parent" android:layout_height="wrap_content">         <EditText android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1" android:id="@+id/editText1" android:text="3">             <requestFocus></requestFocus>         </EditText>         <Button android:text="Button" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button2"></Button>     </LinearLayout> 

and then some other stuff underneath

The problem I'm having is that right when the app starts the focus is on the input, i dont want focus to be on input right when the app starts.

I tried removing the

<requestFocus></requestFocus> 

thing and it didn't do anything.

like image 470
Saad Avatar asked Sep 29 '11 07:09

Saad


People also ask

How do I remove edit text from Focus?

It's fine if it worked for you, I solved it with android:focusable="true" android:focusableInTouchMode="true" in the parent RelativeLayout. This answer totally worked for me, removing focus of editText AND closing keyboard.

How do I turn off edit text on Android?

What should I set to disable EditText? It's possible to preserve both the style of the view and the scrolling behaviour. To disable an EditText while keeping this properties, just use UI. setReadOnly(myEditText, true) from this library.

How do I change focus on text?

Show activity on this post. I have an EditText-Field and set an OnFocusChangeListener for it. When it has lost focus, a method is called, which checks the value of the EditText with one in the database. If the return-value of the method is true, a toast is shown and the focus should get back on the EditText again.

How can I tell if EditText has focus Android?

You can use View. OnFocusChangeListener to detect if any view (edittext) gained or lost focus. This goes in your activity or fragment or wherever you have the EditTexts.


1 Answers

Add the android:focusable="true" and android:focusableInTouchMode="true" elements in the parent layout of EditText as follow;

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/linearLayout7" android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:focusable="true" android:focusableInTouchMode="true"> 

I think, it should help you.

See also;
    Android Developers official guide on handling touch and input

like image 176
Mudassir Avatar answered Sep 23 '22 16:09

Mudassir