首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在android layout xml中,背景、backgroundTint、backgroundTintMode属性有什么不同?

在android layout xml中,背景、backgroundTint、backgroundTintMode属性有什么不同?
EN

Stack Overflow用户
提问于 2015-09-09 12:39:24
回答 3查看 146.2K关注 0票数 127

在使用android layout xml时,我遇到了backgroundTint属性。我不明白这是做什么用的。

还有什么是backgroundTintMode ??

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-06-28 23:31:57

我测试了android:backgroundandroid:backgroundTintandroid:backgroundTintMode的各种组合。

当与android:background一起使用时,android:backgroundTint会将滤色器应用于android:backgroundTintMode的资源。

结果如下:

如果你想做进一步的实验,下面是代码:

代码语言:javascript
复制
<?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>
票数 102
EN

Stack Overflow用户

发布于 2015-09-09 13:16:14

backgroundTint属性将帮助您为背景添加色调(阴影)。您可以以- "#rgb", "#argb", "#rrggbb", or "#aarrggbb".的形式为其提供颜色值

另一方面,backgroundTintMode将帮助您应用背景色调。它必须具有常量值,如src_over, src_in, src_atop,等。

参考this可以清楚地了解可以使用的常量值。搜索backgroundTint属性和描述以及各种属性将可用。

票数 14
EN

Stack Overflow用户

发布于 2015-09-09 13:25:25

BackgroundTint用作滤色器。

FEFBDE作为色调

37AEE4作为背景

尝试通过注释色调/背景来查看不同之处,并在两者都设置时检查输出。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32471009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档