如何在Android键盘上添加按钮

时间:2012-02-07 15:10:44

标签: android keyboard

大家好我在我的项目中分配了一个任务,我需要在Android键盘的顶部添加一个完成按钮。在我的屏幕上我有一个EditText,每当我点击EditText它应该打开一个键盘和"完成" Android键盘顶部的按钮。所以我可以将一个监听器附加到该按钮来执行我的任务。任何建议。

感谢和安培;此致 E.N.Krishna。

2 个答案:

答案 0 :(得分:2)

如果您需要键盘来显示“完成”按钮,则需要在EditText中定义它

    <EditText android:text="EditText" android:layout_width="fill_parent"
android:id="@+id/editText1" android:layout_height="wrap_content"
android:imeOptions="actionDone"/>

然后,当用户使用OnEditorActionListener

按下完成按钮时,您可以捕获
class DoneOnEditorActionListener implements OnEditorActionListener {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        return true;    
    }
    return false;
}

}

答案 1 :(得分:0)

如果您阅读this,就可以找到答案。

即IME行动的概念。