I am trying to build a simple home screen widget with multiple clocks(different regions). Design wise, I want to use a CardView (e.g. the google search bar) as the root layout element, but since its not supported in widgets, how can I replicate it? Can I use its parent class i.e. Frame Layout in some way?
Asked
Active
Viewed 2,589 times
4

Vadim Kotov
- 8,084
- 8
- 48
- 62

Arshdeep Singh Saini
- 65
- 2
- 5
-
I just tried to use a `android.support.v7.widget.CardView` and it says `Problem loading widget`. I guess that's still a limitation. Weird ! – Someone Somewhere Apr 29 '19 at 21:49
1 Answers
7
You can use a supported view class and set the background drawable to the card_drawable defined here:
https://gist.github.com/MarsVard/8297976
For example, to a LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/card_drawable"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Test"
/>
</LinearLayout>
</LinearLayout>

Ivan
- 2,632
- 1
- 24
- 12