Android将回车键变为搜索键

很多应用,打开软键盘进行输入的时候,回车键会自动显示为“搜索”,以前找了很久,不知道如何实现,今天在StackOverFlow上闲逛,偶然间发现,其实很简单,两行代码的事。

只需要设置一下EditText中的inputType和imeOptions两个选项即可,见下面代码中的粗体部分。

 <EditText
                android:id="@+id/searchBox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:imeOptions="actionSearch"
                android:padding="5dp"
                android:hint="@string/searchbox_hint"
                android:textSize="18sp"
                android:singleLine="true"
                android:focusableInTouchMode="true"
                android:background="@drawable/searchbox">
            </EditText>

Happy coding!!!

posted on 2016-06-09 10:00  前端风云志  阅读(1866)  评论(0)    收藏  举报

导航

关注我

前端风云志