android实现widget时钟示例分享

2019-12-10 20:08:55于海丽

<?xml version="1.0" encoding="UTF-8"?>
<appwidget-provider xmlns:android="http://www.easck.com/apk/res/android"
    android:initialLayout="@layout/time_appwidget"
    android:minHeight="40dp"
    android:minWidth="40dp"
    android:updatePeriodMillis="0" />

 

三、在layout文件夹下建立文件time_appwidget.xml:

 

复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/rectangle"
    >
    <TextView 
         android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:text="current time"
        />
</LinearLayout>

 

四、在drawable文件夹下建立rectangle.xml文件(这部可以省略,主要是为了美化TextView控件,渐变效果):

 

复制代码
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://www.easck.com/apk/res/android"
    android:shape="rectangle" >

 

    <!-- 设置弧度 -->
    <corners android:radius="9dp" />

    <gradient