【问题标题】:How to use background, backgroundTint and backgroundTintMode in pre Lollipop devices如何在预棒棒糖设备中使用背景、背景色和背景色模式
【发布时间】:2017-06-12 11:47:53
【问题描述】:

我正在使用

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

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

但这适用于 21 及更高版本。我想要它在 API 17 和 19 中。 我正在扩展 Activity。

【问题讨论】:

标签: android user-interface background android-linearlayout tint


【解决方案1】:

我用过:

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

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

【讨论】:

    【解决方案2】:

    为了绕过 api 21 及更高版本的背景色调,我简单地将 View 作为布局中的第一项。如此纯粹的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>
    

    我也不确定你使用的乘法方法。

    【讨论】:

      猜你喜欢
      • 2015-08-14
      • 1970-01-01
      • 2015-09-13
      • 2014-12-18
      • 2016-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多