Sar*_*glt 101 android android-layout
在使用android布局xml时,我遇到了backgroundTint属性.我不明白是什么.
还有什么backgroundTintMode?
Yog*_*ity 85
我测试了各种组合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>
Run Code Online (Sandbox Code Playgroud)
Zai*_*ain 12
我不会过多强调差异,因为它已经涵盖,但请注意以下几点:
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" />
Run Code Online (Sandbox Code Playgroud)
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_dialog_email"
android:backgroundTint="@color/colorAccent" />
Run Code Online (Sandbox Code Playgroud)
另一个例子
如果你试图改变的强调色FloatingActionButton用android:background你不会注意到一个变化,这是因为它已经被利用app:srcCompat,所以为了做到这一点,你可以使用android:backgroundTint,而不是
| 归档时间: |
|
| 查看次数: |
99298 次 |
| 最近记录: |