在網上查了很多方法,自動彈出,都沒有成功。猜測和Activity剛初始化,不能彈出鍵盤的問題應該一樣,界面未加載完全。給彈出鍵盤加一個延時就行了。EditText獲取焦點,讓其可以彈出軟鍵盤,網上方法很多,而且是正確的,這裏就不寫了。
先是自定義的popupwindows暴露一個對外的方法:
public void setInput() { InputMethodManager imm = (InputMethodManager) context.getSystemService(Service.INPUT_METHOD_SERVICE); imm.showSoftInput(text, 0); }
然後在需要的地方調用:
final InvitePopupWindows pop = new InvitePopupWindows(getActivity()); View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.activity_head_web, null); pop.showAtLocation(contentView, Gravity.CENTER, 0, 0); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { pop.setInput(); } }, 100);
這樣就成功了,希望能幫到大家。