English 中文(简体)
EditText 请求重点
原标题:EditText request focus

我正在设计一个日志:

UserName:  .....

Password:  .....

     LoginButton

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

www.un.org/Depts/DGACM/index_spanish.htm 我使用以下法典:。

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

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

Through xml:

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

Or call onClick method manually.

问题回答

是的,我回答说,只是ed上了“条形”。 档案:

        <activity android:name=".MainActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateAlwaysVisible" />

http://www.un.org/french/ga/president

Thanks..

<代码>youredittext.requestFocus()。 按活动分类

oncreate();

并使用上述法典

有了软键板残疾(只有外部键板才允许),我定下来,将 cur子最终转移到埃德特提尔:

editText.setSelection(editText.getText().length)

• 开展以下活动:

android:windowSoftInputMode="adjustResize"

3. 在意见成熟时确定重点:

fun setFocus(view: View, showKeyboard: Boolean = true){
    view.post {
        if (view.requestFocus() && showKeyboard)
            activity?.openKeyboard() // call extension function
    }
}

我知道它太晚了,但只有解决办法对我来说是行之有效的。

edittext.requestFocus()   
edittext.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN,0f,0f,0))    
edittext.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_UP,0f,0f,0))

我利用这一机会,以方案方式打开主要板块。

你可以写一下你的法典:

if (TextUtils.isEmpty(username)) {
    editTextUserName.setError("Please enter username");
    editTextUserName.requestFocus();
    return;
}

if (TextUtils.isEmpty(password)) {
    editTextPassword.setError("Enter a password");
    editTextPassword.requestFocus();
    return;
}

这在2023年对我做了出色的工作。

在你想要打开钥匙板的活动的明文档案中添加如下内容。

android:windowSoftInputMode="stateVisible"

在活动/筹资中增加

 if (editText.text.isNullOrEmpty()) {
            editText.requestFocus()
        }

If you do nt add this if clause keyboard will open in activity resume state as well.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签