Android Weiget Control First Solution

Source: Internet
Author: User

The basic steps to create a widget are:

1. Write a class inheritance Appwidgetprovider, so you can see that the widget is actually a broadcast, so to register the broadcast in the manifest file

2. Configure in the manifest file

<receiver android:name= "Com.example.mobilesafe.receiver.MyWidget" >
<intent-filter>
< android:name= "Android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>

<meta-data
Android:name= "Android.appwidget.provider"
Android:resource= "@xml/process_widget_provider"/>
</receiver>

2.1 in which receiver name is a subclass of Appwidgetprovider,

Action in the name intent filter actions, do not change;

Finally, create the XML folder under the Res folder and create the Process_widget_provider.xml file in the folder

3.process_widget_provider.xml file

  

<?xml version= "1.0" encoding= "Utf-8"?>
<appwidget-provider xmlns:android= "Http://schemas.android.com/apk/res/android"
android:initiallayout= "@layout/process_widget"
android:minheight= "100dip"
Android:minwidth= "300dip"
android:updateperiodmillis= "0"/>

Android:initiallayout the display layout file for the widget

Android:minheight the display height of the widget

Android:minwidth the display width of the widget

Android:updateperiodmillis the time to automatically update its interface content

4. layout file Android:initiallayout

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:gravity= "Center_vertical" >

<textview
Android:id= "@+id/tv"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_marginleft= "10.0dip"
android:text= "Hello widget"/>

</LinearLayout>

Android Weiget Control First Solution

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.