我正在设计一个登录页面,如下所示:
UserName: .....
Password: .....
LoginButton
当活动开始时,我希望焦点转到“UserName”文本框并出现键盘。
我正在使用以下代码: boolean checkFocus=user.requestFocus();
Log.i("CheckFocus", ""+checkFocus);
if(checkFocus==true)
{
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(user, InputMethodManager.SHOW_IMPLICIT);
}
我不明白在哪里编写代码才能使键盘在活动启动时出现,并将焦点放在“UserName”编辑框上。请问有人可以指导我吗?