Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include a CardView in a home screen widget

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?

like image 238
Arshdeep Singh Saini Avatar asked Mar 11 '23 06:03

Arshdeep Singh Saini


1 Answers

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>
like image 102
Ivan Avatar answered Mar 15 '23 09:03

Ivan