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