Android multi-window switching EditText automatically pops up soft keyboard, Java

Android multi-window switching EditText automatically pops up soft keyboard, Java

For example, when the activity is switched from the foreground to the background, and then switched to the foreground, EditText is required to automatically evoke the soft keyboard when the activity is in the foreground.

Activity needs to be configured in AndroidManifest.xml:

android:windowSoftInputMode="stateAlwaysVisible|adjustPan"

 

import android.os.Bundle;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    private EditText editText;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = findViewById(R.id.edit);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (!editText.hasFocus()) {
            editText.requestFocus();
        }
    }
}

 

 

Android shields and hides the system's own input keyboard_android shields the system keyboard_zhangphil's blog-CSDN blog Android shields and hides its own input keyboard If it is an Activity, configure the Activity attribute in AndroidMainfest.xml: android:windowSoftInputMode="stateAlwaysHidden|stateHidden" https:/ /blog.csdn.net/zhangphil/article/details/80355195

 

Guess you like

Origin blog.csdn.net/zhangphil/article/details/129955891