I have an Android app where a user can (de-)select an image. Images are shown in a ViewPager, nested inside a 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>
The Checkbox is placed towards the bottom right. My issue is that I'd like to change the tint of the Checkbox drawable based on the background behind the checkbox. If it's a dark-ish image, a white tint works great. If the image is very bright, or maybe simply not wide enough to reach the checkbox, then white doesn't work, and gray would be better.
I'm struggling to find a way to determine the visible color in the rectangle to Checkbox is placed. (I know how to change the tint programmatically). Or is there a more elegant solution to changing the drawable tint based on the surrounding color?
Check the dimensions of the image first and determine if it gets to the check box.
If not then Grey.
If so then it would be possible to take a broad portion of the lower half of the image and determine its overall pixel brightness.
With that value it can be determined what color would best stand out over the image.