【发布时间】:2018-05-01 04:46:29
【问题描述】:
我正在开发 android 应用程序,我需要一个具有背景和前景的按钮,它们是一些图标。
我想将 backgroundTint 和 foregroundTint 设置为不同的颜色,因为在编写颜色选择器时会用到它。
问题是当我设置foregroundTint时:
- foregroundTintMode=multiply - 背景色调正常,但前景图标没有改变颜色
- foregroundTintMode!=multiply - 前景色调正常,但背景图标将其颜色更改为 foregroundTint,而不是 backgroundTint
我已经尝试了 foregroundTintMode 和 backgroundTintMode 的所有组合,但没有得到任何结果。
这是我的测试文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_height="match_parent"
tools:context="euroicc.testfb.MainActivity"
android:background="@color/colorPrimary">
<Button
android:id="@+id/button"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@drawable/icon_background"
android:backgroundTint="@android:color/holo_blue_dark"
android:foreground="@drawable/icon_settings"
android:foregroundTint="@android:color/white"
tools:layout_editor_absoluteX="105dp"
tools:layout_editor_absoluteY="141dp" />
</RelativeLayout>
注意:我最初使用 API lvl 17,但更改为 21。我希望这个应用程序支持尽可能多的设备。
【问题讨论】:
标签: android user-interface button tint