回答:
私はの様々な組み合わせをテストしandroid:background、android:backgroundTintそしてandroid:backgroundTintMode。
android:backgroundTintとandroid:background一緒に使用すると、のリソースにカラーフィルタが適用されandroid:backgroundTintModeます。
結果は次のとおりです。
さらに実験したい場合のコードは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:textSize="45sp"
android:background="#37AEE4"
android:text="Background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:textSize="45sp"
android:backgroundTint="#FEFBDE"
android:text="Background tint" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:textSize="45sp"
android:background="#37AEE4"
android:backgroundTint="#FEFBDE"
android:text="Both together" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:textSize="45sp"
android:background="#37AEE4"
android:backgroundTint="#FEFBDE"
android:backgroundTintMode="multiply"
android:text="With tint mode" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:textSize="45sp"
android:text="Without any" />
</LinearLayout>
android:backgroundには、プロパティを設定する必要があります。の場合、フレームワークによってすでに何らかの背景/色が設定されていると思います。android:backgroundTintTextViewButton
このbackgroundTint属性は、背景に色合い(陰影)を追加するのに役立ちます。同じ色の値を次の形式で提供できます-"#rgb", "#argb", "#rrggbb", or "#aarrggbb".
backgroundTintMode一方では、背景の色合いを適用するのに役立ちます。src_over, src_in, src_atop,などの定数値が必要です。
これを参照して、使用できる定数値を明確に理解してください。backgroundTint属性の検索と説明、およびさまざまな属性が利用可能になります。
この違いについてはすでに説明しているので、あまり強調しませんが、以下に注意してください。
android:backgroundTint android:backgroundTintMode API 21でのみ利用可能android:backgroundそのデフォルトの色を変更したい場合は、を使用android:backgroundTintしてシェードを追加できます。例
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_dialog_email" />
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_dialog_email"
android:backgroundTint="@color/colorAccent" />
もう一つの例
FloatingActionButton使用のアクセントカラーを変更しようとしてもandroid:background、変更に気付かないでしょうapp:srcCompat。これは、が既に使用されているためです。そのためには、android:backgroundTint代わりに使用できます。
背景の色合いを適用するために使用されるブレンドモード。
背景に適用する色合い。形態で、色の値でなければならない
#rgb、#argb、#rrggbb、または#aarrggbb。これは、このタイプの値を含むリソース( "@ [package:] type:name"の形式)またはテーマ属性( "?[package:] [type:] name"の形式)への参照でもあります。 。
android:backgroundTintなしandroid:backgroundでのみ使用する場合、この2番目のTextViewは何も変更しません。しかし、私android:backgroundTintはボタンで試します、ボタンの色は私が設定したbackgroundTintの色と同じように見えます。これらのケースについて説明していただけますか?