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

XML布局

android:imeOptions="actionSearch"
android:singleLine="true"  //必需,否则设置actionSearch不生效

<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监听

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;
    }
});
上一篇 Multiple dex files define解决记录
下一篇 Android中ViewPager+Fragment禁止预加载问题
目录
文章列表
1 Android DataBinding 采坑记录
Android DataBinding 采坑记录
2
JavaScript日期格式化与日期校验
JavaScript日期格式化与日期校验
3
Homestead注意问题
Homestead注意问题
4
Android集成Bugly应用升级高级配置
Android集成Bugly应用升级高级配置
5
使用Java暴力搜索文件夹下所有包含指定字符串的文本文件
使用Java暴力搜索文件夹下所有包含指定字符串的文本文件
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。