KeyBoardUtils.java——android鍵盤工具類

來源:互聯網
上載者:User

標籤:

 1 package com.xdsjs.save.utils; 2  3 import android.content.Context; 4 import android.view.inputmethod.InputMethodManager; 5 import android.widget.EditText; 6  7 import java.util.Timer; 8 import java.util.TimerTask; 9 10 /**11  * 開啟或關閉軟鍵盤12  *13  * @author xdsjs14  */15 public class KeyBoardUtils {16     /**17      * 打卡軟鍵盤18      *19      * @param mEditText 輸入框20      * @param mContext  上下文21      */22     public static void openKeybord(final EditText mEditText, final Context mContext) {23 24         //必須要等UI繪製完成之後,開啟軟鍵盤的代碼才會生效,所以要設定一個延時25         Timer timer = new Timer();26         timer.schedule(new TimerTask() {27             @Override28             public void run() {29                 InputMethodManager imm = (InputMethodManager) mContext30                         .getSystemService(Context.INPUT_METHOD_SERVICE);31                 imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);32                 imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,33                         InputMethodManager.HIDE_IMPLICIT_ONLY);34             }35         }, 500);36     }37 38     /**39      * 關閉軟鍵盤40      *41      * @param mEditText 輸入框42      * @param mContext  上下文43      */44     public static void closeKeybord(EditText mEditText, Context mContext) {45         InputMethodManager imm = (InputMethodManager) mContext46                 .getSystemService(Context.INPUT_METHOD_SERVICE);47 48         imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);49     }50 }

 

KeyBoardUtils.java——android鍵盤工具類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.