如何根据背景颜色更改浮动可绘制对象的色调?
How to change tint of floating drawable based on background color?
我有一个 Android 应用程序,用户可以在其中 (de-)select 图片。图像显示在 ViewPager 中,嵌套在 FrameLayout 中。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
.. ViewPager stuff ..
<CheckBox
android:id="@+id/selectImageCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
android:alpha="0.9"
android:button="@drawable/ic_checkbox_36dp"
android:textColor="@color/colorLightGray" />
</FrameLayout>
复选框位于右下方。我的问题是我想根据复选框后面的背景更改可绘制复选框的色调。如果是深色图像,白色色调效果很好。如果图像非常明亮,或者宽度不足以到达复选框,则白色不起作用,灰色会更好。
我正在努力寻找一种方法来确定放置复选框的矩形中的可见颜色。 (我知道如何以编程方式更改色调)。或者是否有更优雅的解决方案来根据周围的颜色更改可绘制的色调?
首先检查图像的尺寸并确定它是否到达复选框。
如果不是那么灰色。
如果是这样,则可以拍摄图像下半部分的大部分并确定其整体像素亮度。
根据该值,可以确定哪种颜色最能突出图像。
我有一个 Android 应用程序,用户可以在其中 (de-)select 图片。图像显示在 ViewPager 中,嵌套在 FrameLayout 中。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
.. ViewPager stuff ..
<CheckBox
android:id="@+id/selectImageCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
android:alpha="0.9"
android:button="@drawable/ic_checkbox_36dp"
android:textColor="@color/colorLightGray" />
</FrameLayout>
复选框位于右下方。我的问题是我想根据复选框后面的背景更改可绘制复选框的色调。如果是深色图像,白色色调效果很好。如果图像非常明亮,或者宽度不足以到达复选框,则白色不起作用,灰色会更好。
我正在努力寻找一种方法来确定放置复选框的矩形中的可见颜色。 (我知道如何以编程方式更改色调)。或者是否有更优雅的解决方案来根据周围的颜色更改可绘制的色调?
首先检查图像的尺寸并确定它是否到达复选框。
如果不是那么灰色。
如果是这样,则可以拍摄图像下半部分的大部分并确定其整体像素亮度。
根据该值,可以确定哪种颜色最能突出图像。