Android-Common code: Change the bottom right corner of the soft keyboard to determine the key style

Source: Internet
Author: User


Default diagram:
1. Setting the EditText pattern in XML
  
 
  1. <EditText
  2. android:singleLine="true"
  3. android:imeOptions="actionDone"
  4. android:id="@+id/searchEt"
  5. android:layout_width="match_parent"
  6. android:layout_height="40dp"
  7. android:layout_toRightOf="@+id/icon"
  8. android:background="@drawable/shape_white"
  9. android:drawableLeft="@drawable/search"
  10. android:drawablePadding="5dp"
  11. android:gravity="left|center_vertical"
  12. android:hint="搜索商品"
  13. android:padding="5dp"
  14. android:textSize="14dp" />
Special Reminder: The input box must be set to single-line mode!!!
2. Listening for input completion events in Java
  
 
  1. searchEt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  2. @Override
  3. public boolean oneditoraction ( textview v int ActionId keyevent event ) {
  4. if (actionId == EditorInfo.IME_ACTION_DONE) {
  5. //自定义的功能
  6. doSearch();
  7. /*隐藏软键盘*/
  8. InputMethodManager imm = (InputMethodManager) v
  9. .getContext().getSystemService(
  10. Context.INPUT_METHOD_SERVICE);
  11. if (imm.isActive()) {
  12. imm.hideSoftInputFromWindow(
  13. v.getApplicationWindowToken(), 0);
  14. }
  15. }
  16. return false;
  17. }
  18. });
3. Common Confirmation Key Style description
  
 
  1. actionNone : 回车键,按下后光标到下一行
  2. actionGo : Go,
  3. actionSearch : 放大镜
  4. actionSend : Send
  5. actionNext : Next
  6. actionDone : Done,确定/完成,隐藏软键盘,即使不是最后一个文本输入框



From for notes (Wiz)

Android-Common code: Change the bottom right corner of the soft keyboard to determine the key style

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.