androidandroid-viewandroid-cardviewandroid-framelayouthome-screen-widget

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?


Solution

  • 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>