Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Background gradient result in color banding

Posted on November 11, 2022 By

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.
READ  [FIXED] android - Data inserted using REST API is lost after rebuilding ASP.NET project
Powered by Inline Related Posts

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

Android Tags:android, linear-gradients

Post navigation

Previous Post: [FIXED] java – How to solve debug issue
Next Post: [FIXED] android – How to solve setting up this payment problem – paypal

Related Posts

[FIXED] android – beginner Gradle error “dependency’s AAR metadata” Android
[FIXED] android – How to rename activity_main.xml after starting a new basic activity project? Android
[FIXED] java – Firestore offline write events Android
[FIXED] kotlin – Unresolved reference : ActivityMainBinding in Android Studio 3.6 Android
[FIXED] kotlin – Using Android Studio, how to display Day(mon,tue,wed etc.), Date, Month and Year from selected date in Datepicker Android
[FIXED] arrays – Problem with using depended spinner (Multiple spinner) in android Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What color are dead flea eggs?
  • What is Indiana vine?
  • What’s the downside of a Chromebook?
  • Is phosphide the same as phosphorus?
  • Why do you need an S bend?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme