2015-09-09 12 views

答えて

47

私はandroid:backgroundandroid:backgroundTintandroid: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> 
+3

ビジュアルは本当にこの質問に素早く答えるのに役立ちます、ありがとうございます。 – Burkely91

+2

この視覚的説明は簡単に理解できるようにgr8です。ありがとう! –

+0

2番目のTextViewの例では、 'android:backgroundTint'のみを' android:background'なしで使用すると、この2番目のTextViewは何も変更されません。しかし、私はボタンで 'android:backgroundTint'を試してみました。ボタンの色は、私が設定したbackgroundTintと同じ色に見えます。これらの事件について説明できますか? –

7

backgroundTint属性は、背景に色合い(影)を追加するのに役立ちます。色の値は、-

のように指定できます。一方、backgroundTintModeは、背景色合いを適用するのに役立ちます。 src_over, src_in, src_atop,などの一定の値を持つ必要があります。

thisを参照して、使用できる定数値を明確にしてください。 backgroundTint属性を検索すると、さまざまな属性とともに説明が利用可能になります。

+0

リンクが壊れている:あなたは、さらに実験したい場合はここでは、コードです

Tint Check

は、ここでの結果です。 – mallaudin

+0

いいえ、そうではありません。もう一度確認できますか? – Samridhi

4

BackgroundTintはカラーフィルタとして機能します。背景

として

色合いなどFEFBDE

37AEE4はコメント色合い/バックグラウンドでの違いを見てみて、両方が設定されているときに出力を確認してください。背景の色調を適用するために使用されるモードをブレンド

2

android:backgroundTintMode

android:backgroundTint

色合いの背景に適用します。 #rgb,#argb,#rrggbbまたは#aarrggbbの形式のカラー値である必要があります。

"@ [package:] type:name")またはテーマ属性(形式: "?[package:] [type:] name)の参照でもあります。このタイプの値を含んでいます。

関連する問題