本文實(shí)例講述了Android開發(fā)之彈出軟鍵盤工具類。分享給大家供大家參考,具體如下:
package com.maobang.imsdk.util;import android.content.Context;import android.view.inputmethod.InputMethodManager;import android.widget.EditText;import java.util.Timer;import java.util.TimerTask;/** * 讓editText獲取焦點(diǎn),彈出軟鍵盤 * Created by Administrator on 2016/11/1. */public class EditTextFocusUtil { public static void getFocusable(final Context context, final EditText editText) { editText.requestFocus(); editText.setFocusable(true); Timer timer = new Timer(); //設(shè)置定時(shí)器 timer.schedule(new TimerTask() { @Override public void run() { //彈出軟鍵盤的代碼 InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, InputMethodManager.RESULT_SHOWN); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY); } }, 300); //設(shè)置300毫秒的時(shí)長 }}希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注