Solution 1 :
I’m pretty sure dithering doesn’t do anything if the pixel format is RGBA8888, and therefore cannot help with the banding between visually-adjacent 24bit RGB hues.
This is probably an Android limitation, which arises from the OpenGL limitation that dithering is only for lower bit depths than 32 bit. OpenGL is the backing implementation of Android’s Views.
So, the solution might be using a PNG file for the gradient with dithering already built-in by your paint program.
Solution 2 :
Surprisingly, adding an alpha channel removed the banding completely in my case.
Just set the alpha value of all the colours to 99%, and this would completely remove the banding.
To set the alpha value, you can add FE
to the beginning of the HEX value, like #FFFFFF
to #FEFFFFFF
OR
Click on the little coloured square besides the line numbers in Android Studio, and then you can change the alpha value.
Problem :
I tried to do some linear gradient on my background for my app, and it resulted with color banding.
What I did:
I created a shape called window_background_app.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns_android="http://schemas.android.com/apk/res/android"
android_shape="rectangle">
<gradient
android_angle="45"
android_endColor="#Fe005694"
android_startColor="#fe2D8ACC"
android_type="linear" />
</shape>
I used that shape in a style to apply to the background:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@drawable/window_background_app</item>
</style>
</resources>
I used that style in the manifest of my app:
<application
android_allowBackup="true"
android_icon="@mipmap/ic_launcher"
android_label="@string/app_name"
android_name="generic_name"
android_supportsRtl="true"
android_theme="@style/AppTheme">
Problem
When starting my app, the background displayed some banding with the gradient background_with_banding
I found in similar questions, (for example this one) that I should:
- Try to set dither to true for the background. Problem: use of dither is deprecated now.
- To set the Pixelformat to PixelFormat.RGBA_8888. Problem: that did not change anything for me.
I got this problem on:
- a OnePlus 5t Api 28 (real device)
- Samsung S8, Api 28 (real device)
- a Pixel 2 Api 24 (emulator)
- a Pixel 2 Api 22 (emulator)
- a Pixel C Api 27 (emulator)
The banding did not appear on:
- Samsung Galaxy J3 Api 22 (real device)
- Samsung SM-T533 Api 22 (real device)
Question
I’m not sure if the problem is due to updates on Android version or of from material (or both). And another problem I had is that a lot of solutions I could find online were quite old (most recent were around 2014).
So my question is:
Are there some new solutions for color banding on gradient since dither=true and pixelFormat=RGBA_8888 ?
Comments
Comment posted by somega
I have this effect in Firefox. I always thought this is wanted behavior to increase performance. Am I wrong?
Comment posted by EPuillandre
@somega can you be a bit more precise please ? Do you mean that on the app firefox on your phone, there are gradient with banding ?
Comment posted by wikipedia
On Firefox on Debian I have colour banding (for years). I always thought this was wanted behavior. But