How to clear focus for EditText?

廉价感情. 提交于 2019-12-02 17:16:52

Set in your parent layout next attributes:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true" >

And now, when activity starts this layout getting default focus.

Also we can remove focus from children views in runtime (e.g. after finishing child editing):

findViewById(R.id.mainLayout).requestFocus();

or

Look in the AndroidManifest.xml element.

android:windowSoftInputMode="stateHidden"

It always hide key board when entering the activity.

you must have mentioned <requestFocus> tag in your editTiext field in XML remove that and run again

You could use set focus on container view. Add to container android:focusableInTouchMode="true", android:focusable="true" and tag requestFocus example:

<RelativeLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusableInTouchMode="true"
    android:focusable="true">
    <requestFocus/>

    <EditText
        android:id="@+id/edit_text_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</RelativeLayout>
Zia Ansari

You can try this:

editText.clearFocus();

where ever you want to clear focus.

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

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.

Roman Nazarevych

Here is the answer EditText, clear focus on touch outside.

Or you can just write widget which will show only text with textView and onClickwill display dialog with EditText where you can edit this text/

Try this

On your Activity Declaration in AndroidManifest.xml add the below code :

android:windowSoftInputMode="stateHidden"

It will prevent the keyboard to popup up when activity becomes visible.

Happy coding :)

Kuldeep Sakhiya

This will do your work:

android:windowSoftInputMode="stateHidden"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!