按钮上的 ForegroundTint "overrides" backgroundTint?
ForegroundTint "overrides" backgroundTint on button?
我正在开发 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。我希望此应用支持尽可能多的设备。
不确定为什么要使用普通 Button
和 foreground
,请改用 ImageButton
:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_settings"
android:tint="@android:color/red"
android:background="@drawable/icon_background"
android:backgroundTint="@android:color/black"
/>
我正在开发 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。我希望此应用支持尽可能多的设备。
不确定为什么要使用普通 Button
和 foreground
,请改用 ImageButton
:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_settings"
android:tint="@android:color/red"
android:background="@drawable/icon_background"
android:backgroundTint="@android:color/black"
/>