Android Development Engineer Anthology-1-hour learning widget widgets Development

Source: Internet
Author: User

Objective

Hello everyone, to bring you Android开发工程师文集-1 小时学会Widget小组件开发 an overview, I hope you like

Learn to use Widgets (widget)

Widgets Widget is very convenient, very quick, can be personalized, their own customization, related features, you can update the latest content in real time.

    • Widget layout, widget configuration, appwidgetprovider and configuration Activity
    • Android Widgets
    • XML layout type: Appwidget Provider
<appwidget-provider  xmlns:android="http://schemas.android.com/apk/res/android" //引用的布局文件 android:initialLayout="@layout/widget" android:minHeight="50dp" android:minWidth="100dp" //设置更新时间 android:updatePerioMillis="66666666"></appwidget-provide>
public class WidgetProvider extends AppWidgetProvider { @Override public void onDeleted(Context context,int[] appWidgetIds){  super.onDeleted(context,appWidgetIds);} @Override public void onDisabled(Context context){  super.onDisabled(context); } @Override public void onEnabled(Context context){  super.onEnabled(context);  } @Override public void onReceive(Context context,Intent intent){  super.onReceive(context,intent);  } @Override public void onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds){ super.onUpdate(context,appWidgetManager,appWidgetIds);}}
//TimerService extends ServiceTimer timer=new Timer();timer.shedule(new TimerTask(){ @Override public void run(){   updateTime(); } },0,1000);}//onDestroypublic void onDestroy(){ super.onDestroy(); timer=null;}//updateTime();private void updateTime(){ String time = simpletime.format(new Date());}

Widgets are desktop widgets, and with widgets, we can do a variety of things directly on the desktop.

Widget use
    • Androidmanifest declaration in Appwidget
    • Appwidget configuration file defined in XML
    • Define widget layout files in layout
    • Create class Inheritance Appwidgetprovider class
//清单文件中<meta-data   android:name="android.appwidget.provider"   android:resource="@layout/widget_setting"/>
//onUpdate()重点@Overridepublic void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.layout_widget); //Intent intent = new Intent(); Intent intent = new Intent(); intent.setClass(context, TestWidget.class);  
//清单文件 <intent-filter>         <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />         </intent-filter>         <meta-data android:name="android.appwidget.provider"            android:resource="@xml/widget_provider"/>      
Summarize
    • This article is about Android development engineer Anthology-1 Hours Learning widget widgets Development, if you have a better understanding, welcome to communicate
    • Positioning: Sharing Android & Java knowledge points, interested to continue to follow

Android Development Engineer Anthology-1-hour learning widget widgets Development

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.