【问题标题】:ForegroundTint "overrides" backgroundTint on button?ForegroundTint“覆盖”按钮上的backgroundTint?
【发布时间】:2018-05-01 04:46:29
【问题描述】:

我正在开发 android 应用程序,我需要一个具有背景和前景的按钮,它们是一些图标。

我想将 backgroundTint 和 foregroundTint 设置为不同的颜色,因为在编写颜色选择器时会用到它。

问题是当我设置foregroundTint时:

  1. foregroundTintMode=multiply - 背景色调正常,但前景图标没有改变颜色
  2. 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


    【解决方案1】:

    不确定您为什么使用普通的Buttonforeground,请改用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"
        />
    

    【讨论】:

      猜你喜欢
      • 2018-10-02
      • 2016-10-14
      • 2015-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-01
      • 1970-01-01
      • 2014-03-23
      相关资源
      最近更新 更多