Android 如何在预棒棒糖设备中使用背景、背景色和背景色模式

Android 如何在预棒棒糖设备中使用背景、背景色和背景色模式,android,user-interface,background,android-linearlayout,tint,Android,User Interface,Background,Android Linearlayout,Tint,我正在使用 <?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"

我正在使用

<?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">

#dd282d50
但这在21岁及以上的人群中有效。我希望它出现在API 17和19中。 我正在扩展活动。

我使用了:

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

它在API 17中工作,我甚至从xml中删除了它,它也在API 25中工作。谢谢。

为了避免使用api 21和更高版本的背景色调,我只需将
视图作为布局的第一项。那么纯xml。在这个视图中,我将使用透明颜色操纵背景,而不是色调。例如

<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>

我也不确定您使用的乘法。

请查看以下答案:
<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>