Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – How to apply backgroundTint to a ViewGroup for API 21?

Posted on November 14, 2022

Solution 1 :

I’m not quite sure what the problem is, but I’ve found a workaround which works for API 21.

view.getBackground().setColorFilter(tint_color, PorterDuff.Mode.SRC_OVER);

has the same effect as

view.setBackgroundTintList(ColorStateList.valueOf(tint_color));

Solution 2 :

I think it might be a problem with LinearLayout try to use LinearLayoutCompat to support older API.

<androidx.appcompat.widget.LinearLayoutCompat
    android_layout_width="match_parent"
    android_layout_height="match_parent"
    android_background="@drawable/mybackground"
    android_backgroundTint="#ff0000"
    android_orientation="vertical">

    <!--Sub views here-->

</androidx.appcompat.widget.LinearLayoutCompat>

What’s the difference between LinearLayout and LinearLayoutCompat Here You can read a little about differences

Problem :

I’ve been trying to apply a backgroundTint to a ConstraintLayout element having a Drawable background. However, the tint is not applied and the layout has the same background color as the drawable (only in API 21; works fine from API 23 upwards). It doesn’t work with LinearLayout and GridLayout either, so I think it might be something to do with ViewGroups. Here’s a simplified version of the element.

 <LinearLayout
        android_layout_height="match_parent"
        android_layout_width="match_parent"
        android_orientation="vertical"
        android_background="@drawable/mybackground"
        android_backgroundTint="#ff0000">

        <!--Sub views here-->

 </LinearLayout>

And here’s the background drawable.

<shape xmlns_android="http://schemas.android.com/apk/res/android">
    <solid android_color="#ffffff"/>
    <corners android_radius="10dp"/>
</shape>

How do I fix this?

Comments

Comment posted by clifordjoshy

This didn’t work. backgroundTint was introduced in API 21, so it can’t be a compatibility issue, right? Anyway, thanks for the help.

Comment posted by this

Yeah, maybe You just can’t use

READ  [ANSWERED] java - Firebase keeps updating using Update method, and does not stop?
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

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

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress