Objective
This is the main implementation of an Android application, static broadcast, dynamic broadcast two ways to change the content of the widget, that is, in the blog on the basis of the experiment to modify, so the focus of this experiment is the realization of appwidget small parts ~
First, let's simply say what the widget is.
The application window widget (widget) is a tiny application view that can be embedded in other applications (such a
For more information about appwidgetprovider, see the official documentation.
Recently, due to a problem, we used
The update cycle in Android: updateperiodmillis does not work. First, there are several reasons, which mean that the Android version is problematic. The other one is that it can only be updated once every 30 minutes on the Internet. Otherwise, the service will be used for updates. The following
is deleted. @Override Public voidondisabled (Context context) {//Enter relevant functionality for if the last widget is disabled } //This method is called when the app Widgt is deleted. @Override Public voidOndeleted (Context context,int[] appwidgetids) { Super. ondeleted (context, appwidgetids); } //Accept broadcast events. @Override Public voidOnReceive (Context context, Intent Intent) {Super. OnReceive (context, intent); } Static voidUpdateappwidget (context context, Appwi
I simply learned about the widget components of Android. And their implementation methods.
First, let's talk about the most commonly used button.
1. Button button
Create a button in the main. xml file
Public class mainactivity extends activity {@ OverridePublic void oncreate (bundle savedinstancestate ){Super. oncreate (savedinstancestate );Setcontentview (R. layout. Main );Button button = (button) findviewbyid (R. Id. Button );Button. setonclickliste
Android provides widgets for date and time.
Date widget
Datepicker and datepickerdialog. datepickerdialog is a simple container for loading datepicker ,. There is a trigger method ondatechangedlistener () and ondatesetlistener () respectively ().
In this example, we set two buttons and a textview. When the button is clicked, The datepickdialog is displayed.
Step 1: some java functions related to time
Ins
1.Widget, App Widget, Web app concept
The original concept of the widget was presented by an Apple engineer named Rose in 98 and was not officially known until 2003, but then numerous large companies began to accept and apply the idea. Now we see the gadget in the Apple system that presses the F4 pop-up Dashboard widget, and the nifty gadgets on the Windows 7 sidebar are called Gadget (widget variants), in addition to the Yahoo widget and other widget products. They have a common feature is the
A desktop part is a part of an application that is placed on the desktop using the Appwidget framework.Res/layout/digitalclock.xmlXML code
XML version= "1.0" encoding="Utf-8"?>
TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/time"
android:textsize="45px"
android:textstyle="bold"
android:textcolor="#FFFFFFFF"
android:background="@drawable/bg"
android:layout_width="wrap_content"
andro
Blog migration-I have migrated my blog to www.ijavaboy.com to better manage it. We are sorry for the inconvenience caused by no updates! New address of this article: Click me
The previous article demonstrates how to develop a widget and how to develop a widgethost application. With this foundation, we know that to add widgets to the desktop, we need to do two things:
1. Implement a desktop application as a widgethost Application
2. You need to alloca
Android-misc-widgets four-direction (up/down) drawer bug fix2013-08-04 08:58:13Tags: bug down top panel slidingdrawer original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://mikewang.blog.51cto.com/3826268/1263802As compared to open source projects, th
pendingintent = pendingintent.getactivity (context, 0, Intent,0); Remoteviews remoteviews=Newremoteviews (Context.getpackagename (), r.layout.example_appwidget); //binds the event handler to the button,//The first parameter is used to specify the ID of the bound processor control; //The second parameter is used to specify which pendingintent will be specified when the event occurs.remoteviews.setonclickpendingintent (R.id.widgetbuttonid, pendingintent); //Update AppwidgetAppwidgetmanager.update
Android preset application icons, shortcut icons, or widgets on the desktopModify the res/xml/default_workspace.xml file and add the following code:
Launcher: packageName = "" // complete package name
Launcher: className = "" // complete package name. Class Name (class for processing main intent)
Launcher: screen = "" // screen where the app icon is located (starting from 0)
Launcher: x = "" // c
1. Introduction to favorites on the desktop
The launcher desktop has four elements in the middle, which are the window widgets of a clock. The following lines are respectively a camera, an Amazon bookmarks, and a folder (the folder contains settings and clock ).
In the code, they are all favorites: appwidget, application, shortcut, and folder.2. view the database
Favorites is stored in the database.
Export the database file data/COM.
CheckBox is a multi-choice button. You can select multiple options in a group. CheckBox is also the most common component in Android.
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
Android: layout_width = "
First, let's look at a reference:
Aremoteviews object (and, consequently, an app widget) can support thefollowing layout classes:
* Framelayout
* Linearlayout
* Relativelayout
Andthe following widget classes:
* Analogclock
* Button
* Chronometer
* Imagebutton
* Imageview
* Progressbar
* Textview
Descendantsof these classes are not supported.
We can see Widget Only the following controls can be used: Analogclock ,Button ,Chronometer ,Imagebutton ,Mageview
To display a View component such as a Button on a custom View, complete the following tasks:
1. overwrite the structure of the parent class in the Custom View class (note that there are two parameters)
Copy codeThe Code is as follows: public class MyView2 extends View {
Public MyView2 (Context context, AttributeSet att)
{Super (context, att );
}
Public void onDraw (Canvas c)
{// Draw the content here
}
}
2. Define the layout FileCopy codeThe Code is as follows:
Androidwidgetservice. Java is the core class of the widget framework. It manages all widgets.
After the system server is started, the process will manage other services)
Creates an appwidgetservice instance and calls the systemready method of appwidgetservice.
In this method, the initialization and loading of widgets are completed, mainly through three tasks.
1. traverse all installation packages and fi
attributes, such as font, color, and padding, to indicate the size of gaps around the component, and background to set the background color.After all this is done, we need to add the newly created textactivity to the Finally, run the project and click the viewtext button on the main interface. The following result is displayed:
Extended learning:
Textview is generally used when you need to display some information, it cannot be input, but can only be set initially or modified in the program,
Previous: http://www.bkjia.com/kf/201208/146229.htmlThis example describes how to use DatePickerDialog and TimePickerDialog in the time dialog box to obtain the time or date input.
DatePickerDialog and TimePickerDialog are both subclasses of AlertDialog. Therefore, they are used in the same way as Alert: Android ApiDemos example resolution (22): App-> Dialog
1. Define the variables for storing the date and time
[Java]// Date and timePrivate int mYea
This example describes the creation and use of the Android programming widget. Share to everyone for your reference, specific as follows:
There is a detailed approach to how to create a widget in the Android reference, and here's a quick overview to see the reference in the Android SDK.
To create a widget, there are several steps:
(1) Create a class to inherit
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.