2

I have a MainActivity with android:windowSoftInputMode="adjustNothing" set in the AndroidManifest. The Theme has parent Theme.AppCompat.Light.NoActionBar. I add a DialogFragment to this activity and show an AlertDialog inside of it, then set alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); inside the fragment.

Now, on Android 5.1.1 it works as expected. The keyboard does not auto show when the dialog is created. When the user taps on an EditText inside of the dialog, the keyboard pops up and resizes the activity so that it won't overlap.

The problem is that on Android M, this doesn't happen. The keyboard is indeed not shown when the dialog is created, but when it pops-up after the user touched an EditText, it overlaps the dialog.

Any idea why this happens on M, but on previous versions everything works fine?

Edit: Apparently after creating a HelloWorld project with only the basics of the issue, I've found out that the below 2 Activity Theme elements cause the keyboard to not resize. If anybody has any permanent solution to this matter, I'm all ears (or rather eyes).

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>
Bogdan Zurac
  • 6,348
  • 11
  • 48
  • 96
  • 1
    Don't you think that so early version of developer OS could be buggy? – Divers Jun 11 '15 at 12:01
  • Well that's the thing. I don't know. It may indeed be a bug like you said. It may not be. I've tried getting in contact with some of the guys on the framework and didn't get an answer, so I thought asking it here, maybe somebody has an idea worth looking into. No biggie I suppose... – Bogdan Zurac Jun 11 '15 at 12:02
  • Well I had a similar issue on earlier android versions. In my case the keyboard was opened behind the dialog and was not useable. I guess this is something similar. – rekire Jun 11 '15 at 14:17
  • Can you provide an small, complete example which illustrates the problem? By "small", I mean it should contain absolutely no code which is unrelated to the problem at hand. By "complete", I mean anyone else should be able to import it into their development environment (such as Android Studio), compile and run, and see exactly the behavior you are asking about. – Code-Apprentice Jun 11 '15 at 14:19
  • @Code-Apprentice thanks for coming up with that idea. I started a new project with only the problematic parts of the app and I think I've figured out what is causing it. Apparently android:windowDrawsSystemBarBackgrounds = true and android:windowTranslucentStatus = true set inside the activity theme are causing the dialog to not resize. I'm not sure what changed compared to L though, that causes this issue. Might be a bug, might just be a change. Should I still upload the sample project just in case? If so, any idea where I can upload it for all of you to check it out? – Bogdan Zurac Jun 11 '15 at 15:03
  • I can't take credit for this idea. I was merely paraphrasing the help section: http://stackoverflow.com/help/mcve. To continue getting help here, you should post the relevant parts of your code so we can look at it. You probably don't need to post the full project as we can easily recreate those details in Android Studio. Just provide the stuff that differs from the default Hello World app that is initially created. You should also consider submitting your app to the Android project so that they can review the issue when you have enough information to let them know what the trouble is. – Code-Apprentice Jun 11 '15 at 16:55
  • Well I already detailed inside of the question the relevant parts of the code. The only thing to add is what I wrote in the previous comment, which is the cause of the problem. That's all there is to it. You can follow the description in the question when creating a HelloWorld project and you'll get the same issue. I'll update the question with the new info. If you have any permanent solution to this matter (as in, still support those 2 Theme elements, but without producing this issue), then this would be great. If not, I'll just add an answer tomorrow with what I've found. – Bogdan Zurac Jun 11 '15 at 17:02
  • I tried both android:windowDrawsSystemBarBackgrounds and android:windowTranslucentStatus, and it seems android:windowTranslucentStatus is the only culprit. When set "android:windowTranslucentStatus" to false, my activity works well with inputmethod. – Bin Feb 05 '16 at 04:16

1 Answers1

2

I've figured out that the following 2 lines from the Activity Theme causes the keyboard to not resize.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

For now, this is a quick fix. If anybody has a permanent solution to maybe retain those 2 lines but also fix the problem, please do post another answer.

Bogdan Zurac
  • 6,348
  • 11
  • 48
  • 96
  • I tested with these two lines and it seems android:windowTranslucentStatus is the only culprit. – Bin Feb 05 '16 at 04:22
  • http://stackoverflow.com/questions/21092888/windowsoftinputmode-adjustresize-not-working-with-translucent-action-navbar – lenhuy2106 Mar 18 '16 at 01:17