EditText 请求焦点 [英] EditText request focus

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

问题描述

我正在设计一个登录页面:

I am designing a login page as:

UserName:  .....

Password:  .....

     LoginButton

活动开始时,我希望焦点转到用户名"文本框并显示键盘.

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

我正在使用以下代码:

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

我不明白在何处编写此代码以在活动开始时显示键盘并且焦点位于用户名"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:

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

或者手动调用 onClick 方法.

Or call onClick method manually.

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

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