[英]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 . 我正在使用android.support.v7.widget.SearchView ,提示图标位于光标的左侧,如图所示。
But i want to make the cursor begins after the hint search icon . 但我想在提示搜索图标后开始光标。
XML: 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,如下所示:
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
必须将android:iconifiedByDefault
更改为app:iconifiedByDefault
and add those two lines to avoid launching the keyboard on starting the activity and it is shown only after clicking searchview 并添加这两行以避免在启动活动时启动键盘,并且仅在单击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 将搜索视图默认设置为单击时设置为false,关闭搜索视图时设置为true
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" 而不是android:iconifiedByDefault =“false”设置app:iconifiedByDefault =“false”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.