1

I am using android.support.v7.widget.SearchView and the hint icon is at the left of the cursor as shown in the image .

enter image description here

But i want to make the cursor begins after the hint search icon .

XML:

 <android.support.v7.widget.SearchView
                android:id="@+id/airlines_searchView"
                android:iconifiedByDefault="false"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:onClick="EnableSearchView"
                android:background="#fbf7f7"
                />

I got the EditText of the search view as following :

EditText search_text=(EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);

and i don't know what are the required properties to set to it .

I checked That but no solutions found, any help please ?

Community
  • 1
  • 1
Asmaa Rashad
  • 593
  • 5
  • 28

3 Answers3

0

Have to change the android:iconifiedByDefault to app:iconifiedByDefault

and add those two lines to avoid launching the keyboard on starting the activity and it is shown only after clicking searchview

android:focusable="false"
android:focusableInTouchMode="true"

So Try this:

 <android.support.v7.widget.SearchView
            android:id="@+id/airlines_searchView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:imeOptions="actionDone"
            android:textStyle="normal"
            android:layout_marginTop="15dp"
            android:background="#fbf7f7"
            android:focusable="false"
            android:focusableInTouchMode="true"
            app:iconifiedByDefault="false"/>
Asmaa Rashad
  • 593
  • 5
  • 28
himanshu1496
  • 1,921
  • 19
  • 34
0

Set search view iconified by default to false on click and to true on close the search view

    searchView.setOnSearchClickListener( new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchView.setIconifiedByDefault( false );

        }
    } );

    searchView.setOnQueryTextListener( new android.support.v7.widget.SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            //do search
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            //do search
        }
    } );

    searchView.setOnCloseListener( new android.support.v7.widget.SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            searchView.setIconifiedByDefault( true );

        }
    } );
Rejsal
  • 121
  • 1
  • 7
0
<android.support.v7.widget.SearchView
                android:id="@+id/airlines_searchView"
                app:iconifiedByDefault="false"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp" 
                android:background="#fbf7f7"
                />

Instead of android:iconifiedByDefault="false" set app:iconifiedByDefault="false"

Nithin Raja
  • 1,144
  • 12
  • 11