Implementing desktop widgets in Android development

Source: Internet
Author: User

In Android development, sometimes our app design more features, need to be more concise as needed to provide users with clearly used features, the desktop widget is a good choice, that is, the app widget, below we use Android Studio to create a simple desktop widget:

    1. Select New->widget->app Wight
    2. Next set up some information about the app widget where minimum Width and M Inimum height is the size of the app widget, and the size we set is shown on the phone is the same size as an app icon.
    3. Next click on the Finish button and you're done. Is it easy to run your app and you can add widgets to your app on the desktop?

< Span class= "token MD md-src" >< Span class= "token lf" > Next look at what Android studio did for us , after you generate the app widget, you'll find three more files in your project.

< Span class= "token MD md-alt" > < Span class= "token lf" > The first one is the Java class of the app widget, The main logic is implemented here, and the class overrides the three methods of the parent class Appwidgetprovider:

  1. < Span class= "token MD md-bang" > < Span class= "token lf" >onupdate () This method is called every time the app widget is updated, and the logic for updating the data is written in this method. For example: TextView update, make a control visible or invisible.
  2. < Span class= "token MD md-alt" > < Span class= "token lf" >  Onenabled () This method is called when the app widget is available, such as when the user is adding our widget, and doing some initialization in the function, such as initializing the database.
  3. < Span class= "token MD md-alt" > < Span class= "token lf" >  Ondisabled () This method will be called when the app widget is unavailable, such as when the user deletes our widget, which in this function can end the resource consumed by the app widget.

< Span class= "token lf" > < Span class= "token MD md-li" >  The second one is a layout file New_app_widget.xml, The layout of our widgets is set inside this. Third is the configuration file for the app widget inside the XML folder,

< Span class= "token p" > These are the implementations of the entire app widget. I hope I can help you ~

< Span class= "token MD md-li" >< Span class= "token MD md-em Md-start" > < Span class= "token lf" > [< Span class= "token MD md-underlined-text" >PS: I developed a small application to make two-dimensional code, interested friends can try ~ ^_^ creative QR code production "

< Span class= "token lf" >

Implementing desktop widgets in Android development

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.