In my app the first view of all my screens is an EditText, so every time i go to a screen the onscreen keypad pops up. how can i disable this popingup and enable it when manually clicked on the EditText????
eT = (EditText) findViewById(R.id.searchAutoCompleteTextView_feed);
eT.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(eT.getWindowToken(), 0);
}
}
});
xml code:
<ImageView
android:id="@+id/feedPageLogo"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@drawable/wic_logo_small" />
<Button
android:id="@+id/goButton_feed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/go" />
<EditText
android:id="@+id/searchAutoCompleteTextView_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/goButton_feed"
android:layout_toRightOf="@id/feedPageLogo"
android:hint="@string/search" />
<TextView
android:id="@+id/feedLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/feedPageLogo"
android:gravity="center_vertical|center_horizontal"
android:text="@string/feed"
android:textColor="@color/white" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ButtonsLayout_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/feedButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/feed"
android:textColor="@color/black" />
<Button
android:id="@+id/iWantButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/iwant"
android:textColor="@color/black" />
<Button
android:id="@+id/shareButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/share"
android:textColor="@color/black" />
<Button
android:id="@+id/profileButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/profile"
android:textColor="@color/black" />
</LinearLayout>
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/feedListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ButtonsLayout_feed"
android:layout_below="@id/feedLabel"
android:textSize="15dp" >
</ListView>
the third view (EditText) is where the focus is.
Thanks @A.B for good solution
this case if you will disable keyboard in edit text , just add android:focusableInTouchMode="false" in edittext tagline.
work for me in Android Studio 3.0.1 minsdk 16 , maxsdk26
Only thing you need to do is that add
android:focusableInTouchMode="false"
to the EditText in xml and thats all.(If someone still needs to know how to do that with the easy way)I found the following pattern to work well for me in code where I want to show a dialog to get the input (e.g., the string displayed in the text field is the result of selections made from a list of checkboxes in a dialog, rather than text entered via the keyboard).
Initial clicks in the text field yield a focus change, a repeated click yields a click event. So I override both (here I don't refactor the code out to illustrate both handlers do the same thing):
Use This to enable and disable EditText....
The best solution lies in the Project Manifest file (AndroidManifest.xml), add the following attribute in the
activity
constructExample:
Description:
Introduced in:
Link to the Docs
Note: Values set here (other than "stateUnspecified" and "adjustUnspecified") override values set in the theme.
Two Simple Solutions:
First Solution is added below line of code in manifest xml file. In Manifest file (AndroidManifest.xml), add the following attribute in the activity construct
android:windowSoftInputMode="stateHidden"
Example:
Second Solution is adding below line of code in activity
We can use any one solution of above. Thanks