简体   繁体   中英

Android SearchView change cursor position after hint icon

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

在此输入图像描述

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 ?

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"/>

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 );

        }
    } );
<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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM