アンドロイドレイアウトxmlで作業している間に、私はbackgroundTint
属性を見つけました。私は何のために理解していない。アンドロイドレイアウトxmlのbackground、backgroundTint、backgroundTintModeの属性の違いは何ですか?
また、backgroundTintMode
とは何ですか?
アンドロイドレイアウトxmlで作業している間に、私はbackgroundTint
属性を見つけました。私は何のために理解していない。アンドロイドレイアウトxmlのbackground、backgroundTint、backgroundTintModeの属性の違いは何ですか?
また、backgroundTintMode
とは何ですか?
私はandroid:background
、android:backgroundTint
とandroid:backgroundTintMode
の様々な組み合わせをテストしました。
android:backgroundTint
は、android:backgroundTintMode
と一緒に使用すると、android:background
のリソースにカラーフィルタを適用します。
<?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>
backgroundTint
属性は、背景に色合い(影)を追加するのに役立ちます。色の値は、-
のように指定できます。一方、backgroundTintMode
は、背景色合いを適用するのに役立ちます。 src_over, src_in, src_atop,
などの一定の値を持つ必要があります。
thisを参照して、使用できる定数値を明確にしてください。 backgroundTint
属性を検索すると、さまざまな属性とともに説明が利用可能になります。
BackgroundTintはカラーフィルタとして機能します。背景
として
。
色合いの背景に適用します。
#rgb
,#argb
,#rrggbb
または#aarrggbb
の形式のカラー値である必要があります。"@ [package:] type:name")またはテーマ属性(形式: "?[package:] [type:] name)の参照でもあります。このタイプの値を含んでいます。
ビジュアルは本当にこの質問に素早く答えるのに役立ちます、ありがとうございます。 – Burkely91
この視覚的説明は簡単に理解できるようにgr8です。ありがとう! –
2番目のTextViewの例では、 'android:backgroundTint'のみを' android:background'なしで使用すると、この2番目のTextViewは何も変更されません。しかし、私はボタンで 'android:backgroundTint'を試してみました。ボタンの色は、私が設定したbackgroundTintと同じ色に見えます。これらの事件について説明できますか? –