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.
Related
Before my app loads I can change the color of the loading screen using
<resources>
<style name="Theme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="android:background">#FF444444</item>
</style>
</resources>
However, if I do this then I can no longer load the material design library's TimePickerView because it says Binary XML file line #57: Error inflating class com.google.android.material.timepicker.TimePickerView and, more importantly, Attempted to get ShapeAppearanceModel from a MaterialButton which has an overwritten background.
Once I remove the above android:background all is well. Except my loading screen is now white.
So, is there a way to change the loading screen colour without the above XML attribute in the hope that I can get material's TimePicker to work? Or perhaps another work around?
(I've found out how to disable the loading screen completely, but the second or so wait is not ideal.)
Here are the possible solutions (the first solved it):
Use android:windowBackground instead of android:background >> requires to use a resources color than a hardcoded one (i.e. #color/some_color)
Use window.decorView.setBackgroundColor(some_color) right after setContentView() call
Set both android:colorBackground & android:windowBackground to have the same color, and remove android:Background
I'm trying to change the color of buttons and their ripples in my Toolbars without affecting the rest of the app, but no matter how many different ways I try, something in the styles "breaks".
So far I've had the best results (as in that breaks other styles the least) by setting colorControlNormal and colorControlHighlight in the root theme of my app, however any other icon that has ?colorControlNormal set for their tint will also inherit this change as well as any ?selectableItemBackgroundBorderless and the color of scrollbars.
Previous attempts that resulted in worse results (or no results at all) count with defining the toolbar style via app theme:
<item name="toolbarStyle">#style/ToolbarStyle</item>
and in the toolbar style defining the colorControl* properties
<style name="ToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="colorControlNormal">#color/blue</item>
<item name="colorControlHighlight">#color/blue</item>
</style>
having absolutely no result whatsoever
The other attempt was made via the theme attribute directly in the Toolbar view:
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ToolbarStyle"/>
Having the result that I wanted, but also changes a lot more than what I desired; the title + subtitle heights become the same height as the toolbar, since android:minHeight is no longer being overriden, but if I override that property in the styles then the search view will lose it's vertical alignment, the back button loses its height, etc. I end up at a point where I can't fix anything else via theme/style alone.
So now I am stuck with no clues in the documentation on how I can just change the icon colors and their respective ripple colors in the Toolbar only without affecting anything else, does anyone know how to do this without having to resort to doing it programmatically?
The styles' inheritance does not allow this to happen. The only way to do this is programmatically.
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'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 have a ListView with some rows and a custom checkbox on the right hand side. On my OS 4.4 Nexus 4 it seems like a gentle gradient is being applied to the list row backgrounds, creating an ugly artifact on the checkboxes (they disappear half way down, and then invert for the bottom half). On other devices I don't see this problem, and I also don't see it in an OS 4.4.2 emulator.
I haven't been able to find any information online about this, so I'm not sure if it's specific to the device, or the exact OS flavor.
Is this something I can disable? If not, what advice should I give my asset designer?
Here's a screenshot:
The Holo.Light theme uses a subtle grey gradient background. It might only be more apparent on one of your devices due to the screen's contrast/brightness.
You can just set the background to solid white by using the android:windowBackground tag in your Activity's theme:
<style name="SolidWhiteTheme" parent="android:Theme.Holo.Light">
<item name="android:windowBackground">#android:color/white</item>
<item name="android:colorBackground">#android:color/white</item>
</style>
And then applying the theme to your activity in your AndroidManifest.xml like so:
<activity
android:theme="#style/SolidWhiteTheme"
...
>
...
</activity>
As Denley mentioned, the reason for this is the default background specified by the Holo.Light theme.
However, since this background is specifically affecting your ListView, I would suggest setting the background of your ListView in your xml file. Code below.
<ListView
android:background="#android:color/white">
Try specifying a background color for your activity (android:background). If the background is not explicitly set, the device may be using it's own device-specific default background, which is why the gradient is only shown on your Nexus 4 and not other devices.