How to make a Material You-like widget with image whose corners are rounded?
It is already made in Google Photo, but how to get the same effect?
Many ways (like ShapeableImageView) are forbidden and impossible to bypass due to restrictions of RemoteView.
These are some additional details for the first suggested answer:
My widget.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/colorBackground"
android:theme="@style/widget_theme">
<ImageView
android:id="@+id/widget_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/MY_IMAGE" />
</LinearLayout>
attrs.xml in res/values folder looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="AppWidgetAttrs">
<attr name="appWidgetPadding" format="dimension" />
<attr name="appWidgetInnerRadius" format="dimension" />
<attr name="appWidgetRadius" format="dimension" />
</declare-styleable>
</resources>
styles.xml in res/values folder looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Widget theme -->
<style name="widget_theme" parent="Theme.Material3.DayNight">
<item name="appWidgetRadius">@dimen/rounded_corners</item>
<item name="appWidgetInnerRadius">@dimen/rounded_corners_inner</item>
<item name="appWidgetPadding">0dp</item>
</style>
</resources>
dimens.xml in res/values folder looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="rounded_corners">16dp</dimen>
<dimen name="rounded_corners_inner">8dp</dimen>
</resources>
I test my app on a virtual Pixel 4a (API 30).
Minumum API is API 24.
Compile and Target SDKs are both API 31.