I have an AlertDialog that comes over my active Activity (this is for a lock app) so i can block system buttons.
public OverlayDialog(Activity activity, boolean backShouldWork, boolean justFinish) {
super(activity, R.style.OverlayDialog);
activ = activity;
WindowManager.LayoutParams params = getWindow().getAttributes();
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
params.dimAmount = 0.0F; // transparent
params.width = MATCH_PARENT;
params.height = MATCH_PARENT;
params.gravity = Gravity.BOTTOM;
getWindow().setAttributes(params);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
getWindow().setFlags(FLAG_SHOW_WHEN_LOCKED | FLAG_NOT_TOUCH_MODAL, 0xffffff);
setOwnerActivity(activity);
setCancelable(false);
}
protected final void onCreate(Bundle bundle) {
super.onCreate(bundle);
hideSystemUI(getWindow().getDecorView());
sp = PreferenceManager.getDefaultSharedPreferences(getContext());
editor = sp.edit();
emergencyType = sp.getInt("emergency", 0);
sequence = new ArrayList<>();
mHandler = new Handler();
mRunnable = new Runnable() {
@Override
public void run() {
if (upPress && backPressed) {
activ.finish();
}
}
};
FrameLayout framelayout = new FrameLayout(getContext());
framelayout.setBackgroundColor(0);
EditText editText = new EditText(getContext());
showKeyboard(editText);
framelayout.addView(editText);
setContentView(framelayout);
}
public void showKeyboard(final EditText ettext) {
ettext.requestFocus();
ettext.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager keyboard = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(ettext, InputMethodManager.SHOW_FORCED);
}
} , 200);
}
The problem is that the softkeyboard is not shown. I tried forcing the input method to be always visible, and to request focus for the edit text, but no luck Anyone encountered this problem ?