Trouble with tabs and translucent statusbar/navigation for android 4.4 - android

I want to add translucent statusbar and navigation to my app (for kitkat) and on most places it works well.
I have a theme with:
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
and in my layouts I have android:fitsSystemWindows="true"
For normal activities this works fine, but I have two activities that make trouble. -> The content is shown behind the statusbar and my actionbar.
One of them is the PreferenceActivity were I fixed it by adding findViewById(android.R.id.list).setFitsSystemWindows(true);
The second is an Activity with ActionBar.NAVIGATION_MODE_TABS and there I can't find the right target for the setFitsSystemWindows(true) call.
I tried with findViewById(android.R.id.content) and findViewById(android.R.id.tabcontent). I also tried to add the xml attribute to the layout of my fragment but no success.

Add a 25 dp paddingTop on your toolbar

Related

Android transparent status bar and custom view insets

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" />

Android Lollipop transparent statusbar

My problem is easy but I need some help
I have a MainActivity, several Fragments and NavigationDrawer. I also use a Appcompat v7
NavigationDrawer is shown behind the statusbar for what I use ScrimInsetsLayout.
In styles I have colorPrimary and colorPrimaryDark(parent is Theme.Appcompat)
In main activity I use setStatusBarColor(Color.TRANSPARENT) to show Drawer in statusbar. So now I have colorPrimaryDark statusbar color and NavigationDrawer in statusbar
Now I created a new Fragment and I need to disable colorPrimaryDark color and make statusbar real transparent
As I said before, setting color to transparent makes it colorPrimaryDark with drawer shown
Setting it to any other color "hides" drawer.
Thanks
Screenshots:
The transparent translucent status bar is available from API 19, create a new values-v19 folder and a styles.xml inside it then update your BaseAppTheme like this:
<!-- Base application theme for v19. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
But, this would make your UI use the space behind StatusBar, so I would suggest adding an extra TOP padding, of 25dp (researched and found every API uses 25dp as StatusBar height even in landscape mode), for devices > API19

KitKat Transucency just on bottom bar and just on one activity

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.

Android KitKat : All my app content appears behind the ActionBar and StatusBar after changing StatusBar color

I've created a separate xml style file targeting KitKat and I've managed to change the color of the status bar. The only side-effect as seen on the picture, all the content is now moved up beneath the status bar. My question is how can I change the color of the status bar without overlaying this or how can I know the exact top margin I need to put on my content so its starts after the ActionBar and not beneath. Of course I need this to behave as expected on all screen sizes and densities. Thank you
values-v19/styles.xml
<style name="ThemeSelector" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
You should add the following to the top of the view(s)
android:paddingTop="?android:attr/actionBarSize"
If you're using the Support Library for the action bar, you need to remove the android: prefix
android:paddingTop="?attr/actionBarSize"
By enabling translucent system bars, your layout will fill the area behind the system bars, so you must also enable fitsSystemWindows for the portion of your layout that should not be covered by the system bars.
EDITED
You can add
android:fitsSystemWindows="true"
in your XML File
Remove from your layout
android:fitsSystemWindows="true"

Android custom titlebar style/theme

I created an activity with a custom titlebar and a button in it, which is extended by all other activites. It works well so far, but when I use an activity whith theme.dialog the titlebar is not shown correct. There is a padding to the left and right of the title and height is limited to 25, I guess.
So I tried the same to the theme.dialog windowTitleSize as I did to the theme. But it showed the same result as if I just change only the title of the normal theme - a padding to the left and right and the wrong height.
After a lot of googling I found at least one solution that works here on stackoverflow. Unfortunately it fixes the padding for the titlebar at runtime with Class.forName() and getField(). I could change the height of the titlebar with layoutParams the same way, but would like to set it all up in xml.
I browsed themes.xml in the ..data/res/values but could not find where the limitation of the layout is set. Finally I tried to extend the normal theme and create a dialog myself. That brought me to Widget.PreferenceFrameLayout and the following errors in my xmls:
In styles.xml "no resource found..." on all "...android:border..."
<style name="MyPreference">
<item name="android:borderTop">20dp</item>
...
</style>
And in themes.xml "no resource found...android:preferenceFrameLayoutStyle"
<style name="MyThemeDialog" parent="android:Theme">
...
<item name="android:preferenceFrameLayoutStyle">#style/MyPreference</item>
...
</style>
How am I supposed to use the given themes and styles the right way to set up the titlebar in theme.dialog?
-----edit-----
I recognized, that the mentioned attributs are not available in the attrs.xml of api8, so sorry for the hasted asked question. Sometimes I just can't see the forest because of all the trees.
Thanks in advance for your help,
Christel

Categories

Resources