1

I am using

<?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="@drawable/background_sign_up"
android:backgroundTint="@color/colorTranslucent"
android:backgroundTintMode="multiply"
android:orientation="vertical"
android:weightSum="10">

and

<color name="colorTranslucent">#dd282d50</color>

But this works in 21 and above. I want it in API 17 and 19. I am extending Activity.

ashishdhiman2007
  • 807
  • 2
  • 13
  • 28
  • 1
    Check out this answer: https://stackoverflow.com/questions/27735890/lollipops-backgroundtint-has-no-effect-on-a-button – jelic98 Jun 12 '17 at 12:05

2 Answers2

2

To circumvent the api 21 and above for my background tint, I simply put a View as the first item in my layout. So pure xml. In this view I will then manipulate the background, not the tint, using a transparent color. E.g

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.HomeFragment"
    android:id="@+id/frameLayout"
    android:background="@drawable/planeWing">

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/semiTransparentDarkBlue">
    </View>

    <TextView
        android:id="@+id/greeting_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:text="@string/greeting_hello"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView"
        app:layout_constraintVertical_bias="0.0" />

</android.support.constraint.ConstraintLayout>

I'm not certain about the multiply method you have used as well.

ZooMagic
  • 616
  • 7
  • 15
1

I used :

linearLayout= (LinearLayout) findViewById(R.id.linearLayout);
linearLayout.getBackground().setColorFilter(ContextCompat.getColor(this, R.color.colorTranslucent), PorterDuff.Mode.MULTIPLY);

and it worked in API 17, and i even removed it from xml, it is working in API 25 also. Thanks.

ashishdhiman2007
  • 807
  • 2
  • 13
  • 28