的EditText要求重点 [英] EditText request focus

查看:79
本文介绍了的EditText要求重点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计一个登录页面:

UserName:  .....

Password:  .....

     LoginButton

当活动开始,我想重点进入用户名文本框,并出现键盘。

When the activity starts, I want the focus to go to "UserName" textbox and the keyboard to appear.

我使用下面的code:

    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);
    }

我不明白的地方写这篇code,使当活动开始,并重点是在用户名EDITTEXT箱键盘出现。任何人都可以请指导我?

I don't understand where to write this code to make the keyboard appear when the activity starts and focus is on the "UserName" editText box. Can anyone please guide me?

推荐答案

编程方式:

edittext.requestFocus();

通过xml:

Through xml:

<EditText...>
    <requestFocus />
</EditText>

或手动调用的onClick方法。

Or call onClick method manually.

这篇关于的EditText要求重点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆