I have a screen with a EditText
ai whenever I enter it already open the keyboard. I wanted to just open the keyboard when I clicked on it.
I tried this but the keyboard is not opening at all:
mItemDescriptionTextView.setFocusable(false);
I have a screen with a EditText
ai whenever I enter it already open the keyboard. I wanted to just open the keyboard when I clicked on it.
I tried this but the keyboard is not opening at all:
mItemDescriptionTextView.setFocusable(false);
To solve this problem open the file AndroidManifest.xml, then in the declaration of your activity add the following line:
android:configChanges="keyboardHidden|orientation|screenSize"
What will prevent the keyboard from appearing when the activity is created is keyboardHidden
.
Example:
<activity
android:name="com.example.activity.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name" >
</activity>
You need to add android:windowSoftInputMode="stateHidden"
within your AndroidManifest.xml
:
<activity
android:name=".SuaActivity"
android:windowSoftInputMode="stateHidden"/>
This flag will hide the keyboard when the user enters their Activity
(even if EditText
has focus).
You can also create a method to hide the keyboard when you want, for example:
public void hideKeyboard(View v) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
Use these attributes in XML:
android:focusable="true"
android:focusableInTouchMode="true"
Use these attributes in your XML where this EditText is, I could only use putting those attributes inside a LinearLayout as below:
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true" />