0

I am using an edittext in xml for search box. I load searchbox as soon as I call the drawer and my keyboard popsup. I would like to make it such that unless the searchbox is touched, keyboard doesnt popup. How do I go about it? Here's my code so far:

<EditText
                android:id="@+id/search_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/searchbox"
                android:gravity="left|center_vertical"
                android:hint="Search"
                android:textColorHint="@android:color/darker_gray"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:imeOptions="actionSearch"
                android:inputType="textNoSuggestions"
                android:paddingBottom="5dp"
                android:paddingLeft="20dp"
                android:paddingRight="30dp"
                android:paddingTop="5sp"
                android:singleLine="true"
                android:textColor="@android:color/darker_gray"
                android:textSize="20dp" />

corresponding class:

    EditText inputSearch;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,    Bundle savedInstanceState) {
        inputSearch = (EditText) view.findViewById(R.id.search_text);

}

ant clues? thanks!

2 Answers2

1

The only solution is to either make sure another element has focus, or to clear the focus in onResume(). Here is a similar question on the topic: Stop EditText From Gaining Focus. You can do this by creating another empty element and setting the attributes android:focusable="true" and android:focusableInTouchMode="true" And you can clear the focus simply by calling clearFocus() on your EditText.

Community
  • 1
  • 1
Bryan
  • 14,756
  • 10
  • 70
  • 125
  • Based on your code, you should be able to call `inputSearch.clearFocus()` in your `onResume()` method. What error are you getting? – Bryan Oct 06 '15 at 12:58
0

Try this, in onCreate

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)

or

go to your application manifest file, and write this line for that activity you want to disable auto keyboard pop-up.

android:windowSoftInputMode="stateHidden"
varunkr
  • 5,364
  • 11
  • 50
  • 99