If you want to clear the default focus for editable text, use the following 2 attributes
android:focusable="false" android:focusableInTouchMode="true"
inside the parent linear layout.
eg:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:focusable="false" android:focusableInTouchMode="true" android:orientation="vertical"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="email id" android:inputType="textEmailAddress" android:maxLines="1" /> </LinearLayout>
If you want to hide the keyboard when creating activity, use these attributes inside the activity tag of the manifest file, for example:
<activity android:configChanges="screenSize|orientation|keyboardHidden" android:screenOrientation="portrait" android:name=".activities.LoginActivity" android:windowSoftInputMode="stateHidden|adjustResize"/>
If you want to hide the keyboard when a button is pressed or when an event occurs, use the following code
public void onClick(View v) { try { //InputMethodManager is used to hide the virtual keyboard from the user after finishing the user input InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isAcceptingText()) { imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); } } catch (NullPointerException e) { Log.e("Exception", e.getMessage() + ">>"); } } } catch (NullPointerException e) { Log.e("Exception", e.getMessage() + ">>"); }
If you want to remove focus from editing text fields after exiting the exercise
@Override protected void onResume() { super.onResume(); mEmail.clearFocus(); mPassword.clearFocus(); }
And finally, if you want to clear the data in the edit text fields when submitting the form, use
@Override protected void onResume() { super.onResume(); mEmail.getText().clear(); mPassword.getText().clear(); }
krishna murthy Jan 05 '18 at 12:01 2018-01-05 12:01
source share