您的位置:首页 > 移动开发 > Android开发

android studio实现页面跳转后edittext获取焦点自动打开软键盘  

2017-05-27 00:00 369 查看
//获取edittext控件,实现在页面跳转后自动打开软件盘

final EditText edittext = (EditText)findViewById(R.id.editText3);

edittext.setFocusable(true);

edittext.setFocusableInTouchMode(true);

edittext.requestFocus();

Timer timer = new Timer();

timer.schedule(new TimerTask() {

public void run() {

InputMethodManager inputManager =

(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

inputManager.showSoftInput(edittext, 0);

}

},

200);

由于刚进去整个view还没构建完毕,弹出软键盘是没有效果的,所以加了个定时器,在进到页面后200毫秒后就会弹出软键盘。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐