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>
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.
Related
I have implemented a custom dialogue fragment which contains a custom view pager and an edittext.View pager contains a grid. To move the view upwards when keyboard is visible I have placed the view inside a scrollview. When app is running view pager is not displaying. How can I make this custom fragment scrollable when keypad is visible. Please help me. Thanks in advance.
Add android:windowSoftInputMode="adjustPan" to the corresponding activity tag in your application manifest file.
In my case I tried everything, however the problem was not in the implementation of the dialog, or how the keyboard was invoked. I was using a theme to make the status bar translucent and that caused the wrong behavior, by changing to another theme the dialog goes up without problems when invoking the keyboard. I hope my answer is helpful
I was using this style
<style name="TranslucentTheme" parent="MyTheme">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:fitsSystemWindows">true</item>
</style>
I've been working on an app and I've reaching the point where it requires me to display a menu window in the middle of the screen.
I've been using an AlertDialog object filled with a custom View but now it was required of me to "surround" the window with a semi-transparent white glow as opposed to the default grayish one. I did a similar with the fade-in color of some navigation drawers I have on my app but in that case I had a specific method to quickly help me solve that problem. So far I haven't found anything that helps me solve this one.
I tried creating a default style with a new "windowBackground" value but I encountered 3 problems from the get-go:
I'm no longer able to shut the AlertDialog down by clicking outside the layout (I'm guessing because by changing the color that way everything is now the layout)
The menu window is now surrounded by a black outline that wasn't there before
By using the filtering search inside the layout, which manipulates the members of a list, the window collapses on itself
Is there any way to accomplish what I want more or less directly?
I'm not really sure about it, but you can use this in your styles.xml
<style name="MyDialogTheme" parent="android:Theme.AppCompat.Light.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/your_light_color</item>
<item name="android:backgroundDimEnabled">false</item>
And if you want to dismiss the dialog when clicking outside, use this:
dialog.setCanceledOnTouchOutside(true);
or
<item name="windowCloseOnTouchOutside">true</item>
in your styles.xml
I have a LoginActivity where I use an AppCompat theme like this:
<activity
android:name=".LoginActivity"
android:theme="#style/Theme.AppCompat.Light.Dialog"
android:label="Login" />
I am aware that as of this post Google has not yet added Material Themes in AppCompat library for DIALOGS, so I assumed it will fall back on Holo. Instead, this is what I get:
Keep in mind, I am not using the AppCompat toolBar. In the Activity, I am not even making a reference to the ActionBar. What you see above is default behavior, yet I cannot figure out where it is coming from. Is this a bug perhaps?
(Also, the EditText fields are not being colored with the Primary color for the app.)
Note: see my final edit for possibly the best solution
For what it's worth, I do think this is a bug. However, a valid workaround that I discovered is to use #style/Base.Theme.AppCompat.Light.Dialog.FixedSize. Based on your screenshot I think this will work for you as well. However, I have not tested palette coloring yet.
From what I can tell in my testing, this extends the gray border while still allowing you to use AppCompat and v21.
Edit: one side-effect is it now appears that all dialog activities are the same size, which may not work for you. Also, I haven't figured out how to remove the title - requestWindowFeature and supportRequestWindowFeature with Window.FEATURE_NO_TITLE seems to be causing
java.lang.RuntimeException: Unable to start activity ComponentInfo{myclass}:
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
even though I've tried it before and after super.onCreate and definitely before setContentView
Edit#2: Removing the title via XML theming works, and since you have no title there is no bizarre gray box to worry about, which means you can drop the FixedSize setting and the dialog will wrap it's content like it did in earlier versions.
<style name="MyActivityDialogTheme" parent="Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
Edit #3: You can also just simply remove the gray background - this may be the best solution because it does not require the Base. prefix:
<style name="MyTitledActivityDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">false</item>
<item name="android:windowTitleBackgroundStyle">#android:color/transparent</item>
<item name="windowActionBar">false</item>
</style>
I modified my theme using the following style (part):
<item name="android:scrollbarTrackVertical">#drawable/scrollbar_1</item>
<item name="android:scrollbarThumbVertical">#drawable/scrollbar_2</item>
(plus of course drawable definition).
However it only works with activity. When activity opens dialog (DialogFragment), scrollbars are standard ones, not mine. Why?
Any help?
I run an app in fullscreen mode where fullscreen is defined as a theme in xml for the entire app.
<style name="MyAppTheme" parent="android:Theme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#null</item>
</style>
Generally it works ok, but there are some issues in some cases:
when I open the search dialog via search button -> Screenshot
when I open spinner widgets that are very long and fill the screen (so that the list is usually scrollable) -> Screenshot
The problem is that when I open the search dialog or spinner widget, the system notification bar occurs for a few millisecs and then scrolls off the screen again.
Please see the screenshots linked above.
I'm currently on 2.2 with NexusOne, but same thing happened on 2.1update1 (esp. case 2) as well before.
The only way to avoid it is to turn off all animations under device settings / display / animation.
I just see it's a known bug: http://code.google.com/p/android/issues/detail?id=3674
Add this line of code after you create the dialog, but before setContentView:
Dialog dialog = new .....
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
dialog.setContentView....