Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText is selected automatically when project is run [duplicate]

I have a problem. In the first Activity of my app I have an EditText at the very top of the page inside a linear layout. Problem is that when i run my app, always the EditText is selected for which a keyboard appears on the screen. Is there any way to tell the app not to have the EditText already selected when the app runs? Thanks in advance, Waiting for your reply...

like image 214
Shanzid SHaiham Avatar asked Jan 22 '26 16:01

Shanzid SHaiham


2 Answers

You can make a method and call it on onCreate() method:

public static void hideSoftKeyboard (Activity activity, View view) {
 InputMethodManager imm =(InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
 imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);}

or simply you can add in manifest file like this:

<activity android:name="com.your.package.ActivityName"
      android:windowSoftInputMode="stateHidden"  />
like image 169
Shani Goriwal Avatar answered Jan 24 '26 07:01

Shani Goriwal


use this code..whenever your project is on, edit-text selected. you will type instantly..

     <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:ems="10" >
     </EditText>
like image 21
harikrishnan Avatar answered Jan 24 '26 07:01

harikrishnan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!