对于手机桌面小部件大家都不会模式,比如桌面上的时钟,天气,日历等等,都属于widget。
简单做个widget小部件,先看一下效果图。
只是在桌面显示个时间,每过一秒刷新一次。
接下来上代码:
首先需要在Layout中新建个布局widget.xml此布局为桌面上要显示的内容,在里面放个TextView
<?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"> <TextView android:id="@+id/time" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>