代码如下:
<EditText
android:id="@+id/country_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@null"
android:hint="@string/search_hint"
android:maxLines="1"
android:paddingLeft="10dp"
android:textColorHint="@color/color_1F3F59_transparent50"
android:textCursorDrawable="@null"
android:imeOptions="actionSearch"
android:inputType="text"
android:textSize="@dimen/dip_14" />
重要属性:
android:imeOptions="actionSearch"
android:inputType="text"
按钮实现的监听:
mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH){
String input=mEditText.getText().toString();
if(!TextUtils.isEmpty(input)){
getPresenter().searchCountry(input);
}
return true;
}
return false;
}
});