Android EditText添加android:imeOptions="actionSearch"设置弹出的键盘中带有搜索按钮

XML布局

1
2
android:imeOptions="actionSearch"
android:singleLine="true" //必需,否则设置actionSearch不生效
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<me.yezhou.lib.ui_widget.common.ThemedEditText
android:id="@+id/et_search_input"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="center"
android:background="@drawable/selector_button_rect_white_blue"
android:gravity="center_vertical"
android:hint="@string/search_input_hint"
android:imeOptions="actionSearch"
android:singleLine="true"
android:paddingLeft="30dp"
android:paddingRight="10dp"
android:textColorHint="#aaaaaa"
android:textSize="13sp"
/>

设置OnEditorActionListener监听

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mEtSearchInput.setFocusable(true);
mEtSearchInput.setFocusableInTouchMode(true);
mEtSearchInput.requestFocus();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
InputMethodManager inputManager = (InputMethodManager) mEtSearchInput.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(mEtSearchInput, 0);
}
}, 1000);

mEtSearchInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
KeyBoardUtil.hideKeyBoard(mEtSearchInput);
if (actionId == EditorInfo.IME_ACTION_SEARCH) {

}
return true;
}
});

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :