安卓EditText点击后虚拟键盘回车变成搜索和事件

本文介绍了如何在Android中将EditText的回车键功能改为搜索,通过设置android:focusable和android:focusableInTouchMode属性为true,以及在EditText中添加android:imeOptions="actionSearch"。示例代码展示了在Toolbar布局中应用此方法,适用于需要自定义搜索功能的场景。
摘要由CSDN通过智能技术生成

android:focusable=“true”

android:focusableInTouchMode=“true”

EditText中加入

android:imeOptions=“actionSearch”

就完事了!

举例

假设一个Toolbar布局,输入框是EditText,那么就在父布局中LinearLayout或者在android.support.v7.widget.Toolbar中加入上面的两句,然后再EditText中加入android:imeOptions=“actionSearch”

<android.support.v7.widget.Toolbar

android:id=“@+id/toolbar”

android:layout_width=“match_parent”

android:layout_height=“50dp”

android:background=“#ff534c”

android:fitsSystemWindows=“true”

android:focusable=“true” //父布局中加入这一句

android:focusableInTouchMode=“true” //父布局中加入这一句

android:scrollbarSize=“13sp”>

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:background=“@drawable/head_search”

android:orientation=“hori

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值