KitKat Transucency just on bottom bar and just on one activity - android

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.

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

Style Android ActionMode bar

I'm trying to style the ActionMode bar. I want the bar to remain the same except for some margin on the right (end).
<style name="GalleryActionMode" parent="#android:style/Widget.Material.ActionMode">
<item name="android:paddingEnd">56dp</item>
<item name="android:layout_marginEnd">56dp</item>
</style>
I'm not interested in the padding, but I used it as a test and the padding adjustment works. Margin, however, has no effect. I imagine this might be related to some unusual way it enters the existing layout. Is there some way to style the layout of the ActionMode bar?
I could not find a way to do this natively, but in my searching I found a great (and tiny) library that can be used as a replacement for the CAB that behaves more like a toolbar. It was easily customizable and almost plugs right into the existing CAB model.
https://github.com/afollestad/material-cab/

Possible overdraw: Root element paints background in Theme.Holo

I have read similar questions for this problem but i couldn't find my answer anywhere. In order to solve the overdraw problem i use the following:
<style name="MyTheme" parent="#android:style/Theme.Holo">
<item name="android:windowBackground">#null</item>
</style>
When i use this in my activity which has an ActionBar, the background color of the action bar also changes to null. How can i fix this? If i set the color of the action bar separate the blue divider is being disappeared. How can i set to null the background of the frame below to action bar divider?
I'd suggest the following:
Create 2 separate themes: one for the activity with the action bar, the other one for the one without it.
For the activity without the action bar, use the theme you provided in your post, i.e.:
<style name="MyTheme" parent="#android:style/Theme.Holo">
<item name="android:windowBackground">#null</item>
</style>
For the activity with the action bar, simply create a theme which doesn't have the android:windowBackground item but instead sets a specific background colour that you want to have in that activity. Then, in the layout file that you inflate for the activity, delete the android:background attribute (because it'll already be set by the theme).
To make it a bit more visual, the theme would look like this maybe:
<style name="MyThemeForActivityWithoutActionBar" parent="#android:style/Theme.Holo">
<item name="android:background">#android:color/black</item>
</style>
And the activity's layout would maybe look like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black" // remove this
android:orientation="vertical" >
...
</LinearLayout>
I indicated which line I'd remove in the snippet above.
Does this help? :)
Solve your overdraw problem in a different way. Set the background you need in android:windowBackground and instead remove backgrounds from your layouts. Then you'll get action bar background back.
Using null window background is a bad solution anyway, exactly because it causes unintended side-effects, like rendering artifacts (or in your case missing action bar background). Chet Haase explains it in detail in Developing for Android VIII
The Rules: User Interface:
Avoid Null Window Backgrounds
One technique to avoid overdraw is to eliminate the window background
in situations where the views in the hierarchy all have opaque
backgrounds. That is, the user will not see the background of the
window if the view hierarchy completely covers that background with
one or more opaque views.
Eliminating the window background can be a valid technique, but it
tends to be a complicated way to solve overdraw issues, and can often
result in rendering artifacts in different situations. While it is
possible to set a null window background in the application manifest,
this can result in graphics artifacts due to the system not being able
to draw the starting window correctly. A more correct way to do this
is to leave the starting window background in place in the manifest,
but set it to null in the activity’s onCreate() method, by calling
getWindow().setBackground(null). But even this approach can cause
artifacts. For example, if the keyboard/IME is set to adjustResize and
is then animated in for an activity that has a null background, there
may be artifacts behind the keyboard as it animates in because the
window manager has nothing to draw for that background. Also,
fullscreen ListViews may have artifacts with overscroll bounce gaps
(which can be worked around with
ListView.setOverscrollFooter/Header()).
The correct way to address overdraw issues for this situation is to
actually use the starting window. Instead of having containers with
their own opaque background color between the window background and
views, put the background drawable you want on the window itself with
the windowBackground theme attribute and let those intervening
containers keep their default transparent backgrounds.

Trouble with tabs and translucent statusbar/navigation for android 4.4

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

ActionBar's action items not working on some devices

I'm developing an app using ActionbarSherlock for backwards compatibility, and I'm currently having problems with the Spinner I add to the ActionBar.
Scenario:
I'm using ActionBar.NAVIGATION_MODE_TABS and each tab is a Fragment with it's own inflated menu.
I have no problem inflating and populating the menus or Spinners, but the problem is that the Spinner is not expanding when a user clicks it. However, when the user slides to another fragment the Spinner expands (and is shown in the wrong fragment), and when sliding back again the Spinner works as expected in the correct fragment.
This problem only occurs on devices <4.0.x (haven't tried 3.x). When testing on >4.0.x it works as expected.
I have tried debugging and going through callback methods, but I can't figure out why this happens. Can it be a bug in older versions of Android, or is it because menus and such are handled differently? (shouldn't though since I'm using ActionbarSherlock).
Does anyone have an idea of why this is happening?
EDIT:
I noticed that the problem occurs to the fragments/tabs that are not added first to the ViewPager, no matter what action item is in the menu. The first tab, i.e. the one that is active once the Activity starts, never has this problem.
Is it just me who is missing something, or is this how it's supposed to be?
Try this, It might help you
For spinner
<com.actionbarsherlock.internal.widget.IcsSpinner
android:id="#+id/spinner_id_name"
style="#style/your_style_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:scrollbars="none" />
In style.xml you apply this
<style name="your_style_name">
<item name="android:dropDownWidth">fill_parent</item>
<item name="android:background">#drawable/spinner_background</item>
<item name="android:popupBackground">#drawable/spinner_dropdown_background</item>
<item name="android:divider">#color/gray_darkest</item>
<item name="android:alignmentMode">alignBounds</item>
<item name="android:dividerHeight">2dp</item>
<item name="android:scrollbars">none</item>
<item name="android:scrollbarAlwaysDrawVerticalTrack">false</item>
<item name="android:scrollbarTrackVertical">#android:color/transparent</item>
<item name="android:dropDownSelector">#android:color/holo_dark</item>
<item name="android:requiresFadingEdge">none</item>
</style>
I had a very similar problem. In my case the Activity was extending another one and the "parent" activity was returning false in onPrepareOptionsMenu() function. This was causing wrong behaviour on Android 2.x, on Android 4 all was OK. When I changed the code to return true all is fixed. Another very strange thing I noticed was that the non-working ActionItem icons where darker then the good ones (in another Activity).

Categories

Resources