[英]How to add a Button on top of an Android keyboard
Hi guys i was assigned a task in my project,there i need to add a Done button on the top of Android keyboard.In my screen i have an EditText,whenever i click on the EditText it should open a keyboard along with the "Done" Button on the top of an Android keyboard.So that i can attach a Listener to that button to perform my task.Any Suggestions. 大家好我在我的项目中分配了一个任务,我需要在Android键盘的顶部添加一个完成按钮。在我的屏幕上我有一个EditText,每当我点击EditText它应该打开一个键盘和“完成” “Android键盘顶部的按钮。所以我可以将一个监听器附加到该按钮来执行我的任务。任何建议。
Thanks&Regards, ENKrishna. 感谢和问候,ENKrishna。
If you need the keyboard to display the Done button, you need to define this in your EditText 如果需要键盘来显示“完成”按钮,则需要在EditText中对其进行定义
<EditText android:text="EditText" android:layout_width="fill_parent"
android:id="@+id/editText1" android:layout_height="wrap_content"
android:imeOptions="actionDone"/>
You can then catch when the user presses the Done button by using OnEditorActionListener
然后,您可以在用户使用
OnEditorActionListener
按下“完成”按钮时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;
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.