I got a fragment which is contained inside a PageViewer which is inside a TabHost inside an activity. The fragment contains only a linear layout with a list view and under it an edit text. I have added a border around the edit text by using an xml of a rectangle shape and adding it as a background.
The activity itself is declared like this:
<activity
android:name=".MyAcivity"
android:label="#string/app_name"
android:theme="#style/CustomActivityTheme"
android:windowSoftInputMode="adjustPan">
</activity>
The theme:
<style name="CustomActivityTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionMenuTextColor">#color/blue</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
When pressing the edit text, the soft keyboard is appearing and it's hiding both the action bar and the tab host. It's also hiding the bottom part of the border around the edit text.
I have already tried switching from adjustPan to adjustResize but adjustResize got no effect at all on the layout and is acting the same as if I didn't declare it at all.
What can be done?
I eventually didn't even need the WindowSoftMode property. What confused me was the fact that the EditText was getting smaller when I pressed it and the soft keyboard was shown. Inside the fragment I had a list which had a height weight of 0.9. When I changed it to 0.85 it was fixed. I guess it was too much for edit text to handle when the keyboard was shown.
Related
I want to draw my layout behind transparent status bar.
I'm using conductor's controllers for implementing my app's screens, all of them have white status bar but one need it to be fully transparent. I can't use windowTranslucentStatus flag when entering this controller because it causes my layouts to jump a little bit when controller enters and exists the screen. I think that custom window insets could help to have one controller to be drawn behind status bar without layout's jumping but I can't figure out how to it. Could anyone help me with this please?
Use android:fitsSystemWindows="true" in the root view of your layout.
What does fitsSystemWindows do?
System windows are the parts of the screen where the system is drawing either non-interactive (in the case of the status bar) or interactive (in the case of the navigation bar) content.
Most of the time, your app won’t need to draw under the status bar or the navigation bar, but if you do: you need to make sure interactive elements (like buttons) aren’t hidden underneath them. That’s what the default behavior of the android:fitsSystemWindows=“true” attribute gives you: it sets the padding of the View to ensure the contents don’t overlay the system windows.
Source
To do that I would recommend you to hide the status bar and enable full screen window. Try below, it works.
Step 1: Create theme in style.xml
<style name="FullScreen" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
Step 2: Apply the theme for activity in manifest file, can also apply theme at the application level too. For example have added in activity level.
<activity
android:name=".MainActivity"
android:theme="#style/FullScreen" />
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>
Background
I have a login Activity , which has a layout as such (vertically, from top to bottom) :
title (logo ImageView and TextView)
image&viewPager that takes the rest of the screen
EditTexts&login button, appear on top of #2 (covering a part of them), but at the bottom of the screen
I need to have this activity full screen, hiding the status bar, and when the soft keyboard appears, change the layout a bit for what's shown above #3 .
The problem
It seems that the combination of those requirements are quite problematic.
I have 2 main issues with them:
What I've made for sensing the soft-keyboard being shown- doesn't seem to work here even though it worked fine on other Activities.
When the soft-keyboard appears, it either re-shows the status bar, or it moves the content above the bottom area (#3) instead of resizing it, while also hiding the button at the bottom (of #3) and showing only the EditText as the first view above the soft-keyboard.
Since there is no way to really have a listener for when the soft-keyboard is shown/hidden, I had to create a customized layout that just tells me when its size has changed. When its height is reduced, I assume the keyboard is shown, and vice versa.
What I've tried
I've tried multiple variants of the layout. Doesn't seem to help
I've used this layout as the root of the fragment, to check if the soft-keyboard is shown (as it changes its size) :
https://stackoverflow.com/a/25895869/878126
Sadly, it works on all other activities except for this one.
I've tried various "windowSoftInputMode" values, including "adjustResize" and "adjustPan"
I thought the issues were because I use a transparent navigation bar, so I've disabled it and also disabled "fitsSystemWindows" for the bottom area (#3) .
I've tried this way to hide the status bar:
requestWindowFeature(Window.FEATURE_NO_TITLE);
and also this way:
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
} else
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
The current layout
here's a short description of the current layout:
<LayoutSizeChangedSensorFrameLayout>
<RelativeLayout>
#1
<LinearLayout vertical, aligned to parent-top>
<ImageView/>
<TextView/>
<CirclePageIndicator/>
</LinearLayout>
#2
<ImageView aligned to parent-bottom, and below #1 />
<ViewPager aligned to the ImageView from all sides/>
#3
<LinearLayout vertical, aligned to the parent-bottom>
<TextView/>
<EditText/>
<Button/>
</LinearLayout>
</RelativeLayout>
</LayoutSizeChangedSensorFrameLayout>
And this is the theme of the activity:
<style name="AppTheme.Material" parent="#style/Theme.AppCompat.Light.DarkActionBar">
...
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentNavigation" tools:ignore="NewApi">true</item>
<item name="android:windowTranslucentStatus" tools:ignore="NewApi">true</item>
<item name="android:navigationBarColor" tools:ignore="NewApi">#android:color/transparent</item>
</style>
The question
How come hiding the status bar doesn't work permanantly, or it affects what's shown when showing the soft-keyboard ?
How come my customized layout can't sense that the soft-keyboard is shown?
Are there any other ways to achieve what I've tried?
I managed to keep the status bar hidden when the soft keyboard shows, by doing the following 2 steps:
Adding the following in the onCreate of the activity:
//No title bar is set for the activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
//Full screen is set for the Window
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Setting windowFullscreento truein the theme:
<style name="CustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
</style>
Unfortunately this is not a complete answer, but it might help you get some of the way.
In addition to adding FLAG_FULLSCREEN to window,
FLAG_FORCE_NOT_FULLSCREEN - this flag can also be cleared:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
I'm trying to make just one activity of my app overflowing behind the software keys, like this
What I already did was to put in my theme definition the following statements
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
and then enabled it on the listView I wanted to overlap
android:fitsSystemWindows="true"
android:clipToPadding="false"
What happened was that my app did overlap on status bar and button bar, but this on EVERY activity and not just on the one I put the two rows above.
Also, it messed up my activity margins: the first row of my application drawer is hidden, and the top of my main fragment as well.
I thought fitsSystemWindows was meant to solve this kind of issues, so I added it to my theme
<item name="android:fitsSystemWindows">true</item>
but nothing changed.
So the question is apparently simple: how can I get the translucent bottom bar, with one of my activities flowing behind it, without messing up the top part of my app and without (if possible) having the same effect on all other activities?
Thank you in advance to each of you fellow helpers.
As Eluvatar stated if I need to have this effect on just one activity the best thing to do is to define a custom theme and assign it just to this activity. That's what I did, I defined an empty style in styles.xml and overrided it in values-v19/styles.xml putting just
<!--<item name="android:windowTranslucentStatus">true</item>-->
<item name="android:windowTranslucentNavigation">true</item>
Then I assigned - in AndroidManifest.xml, the proper style to the activity by using
android:theme="#style/Theme.Style.I.Created.For.This.Activity"
Disabling the first row allowed the activity to just overlap the navigation bar without popping out on the status bar. Margins seem ok as well.
I hope this is going to help somebody else someday.
I'm using this tutorial:
http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
I set a drop down list theme like this
<!-- style the list navigation -->
<style name="MyDropDownNav" parent="android:style/Widget.Holo.Light.Spinner.DropDown.ActionBar">
<item name="android:textColor">#ffffff</item>
</style>
and now pressing the spinner causes it to show up centered on the screen instead of as a drop down. Has anyone run into this? I'm using exactly what they said in the example. Even if I remove the text color and just have the empty style that is based on the parent, the spinner appears in the middle of the screen. Has anyone discovered a way to fix this?
Edit: One more thing I forgot to mention, the style does not even update the text to be white.
Found the solution, the parent is incorrect in the example. It should be:
parent="android:style/Widget.Holo.Light.Spinner"