首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android:编辑文本Go按钮

Android:编辑文本Go按钮
EN

Stack Overflow用户
提问于 2010-07-19 01:05:42
回答 2查看 43.3K关注 0票数 59

我有一个定义如下的Edit Text。

代码语言:javascript
复制
<EditText  
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text" 
android:hint="@string/field_text"
android:id="@+id/field"
/>

我想设置一个自定义命令,这样当有人单击屏幕键盘上的Done/Go按钮时,就会单击一个按钮,或者只运行该按钮运行的方法。我认为这与ime选项有关,但我还不能弄清楚它们是如何工作的。提前感谢您的帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-07-19 04:59:47

你想要android的组合:imeOptions和setOnEditorActionListener

代码语言:javascript
复制
<EditText android:id="@+id/some_edittext"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:imeOptions="actionSend">
</EditText>


some_edittext.setOnEditorActionListener(new OnEditorActionListener() {
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEND) {
            some_button.performClick();
            return true;
        }
        return false;
    }
});

显然,您应该将actionSend更改为您想要的操作,并相应地更新IME_ACTION_SEND。

票数 141
EN

Stack Overflow用户

发布于 2010-07-19 04:13:32

看一下setImeActionLabel方法(或imeActionLabelimeActionId属性)和setOnEditorActionListener,以设置一个监听器来响应事件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3276448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档