Android Learning note-Development components 3

Source: Internet
Author: User

  1. Notification class component

    (1) Toast components: usually appear at the bottom of the screen, black border, showing a period of time automatically disappear, will not interrupt user action.

    Scenario: Download complete, update complete, charging end, installation successful, etc.

    Toast.maketext (This, "Download Done", Toast.length_short). Show ();

    (2) Notification component: notifications on the status bar

    Features: Notification with global effect, not strong timeliness.

    Scene: SMS, missed calls, downloads, etc.

    Get Notification Manager Notificationmanager Object

    Mnitificationmanager = (Notificationmanager) getsystemservice (Context.notification_service);

    Create a Notification object

    Notification Notification = new Notification (r.drawable.xxx, "xxx", System.currenttimemillis ());

    Set a specific jump

    Intent Intent = new Intent (this,secondactivity.class);

    Click to jump after setting the dropdown

    Pendingintent pendingintent = pendingintent.getactivity (this,0,intent,0);

    Setting the drop-down display

    Notification.setlatesteventinfo (This, "10086", "arrears ...", pendingintent);

    Send Notifications

    Mnotificationmanager.notify (notifyid_1,notification);

    Set the status bar notification to automatically disappear after clicking

    Notification.flags = Notification.flag_auto_cancel;

    Cancel Notification

    Mnotification.cancel (notifyid_1); Clear notification with ID number notifyid_1

    Mnotification.cancelall (); Clear all Notifications

    Add permissions to the manifest file

    Flash permission

    Android.permission.FLASHLIGHT

    Vibrator Permissions

    Android.permission.VIBRATE

    (3) Dialog Component: dialog box component

    Scenario: Whether to exit, whether to install, whether to pay

    Features: Interrupting user actions

    Way One:

    Get the object of Alertdialog construction class

    Alertdialog.builder Bulider = new Alertdialog.builder (this);

    Set some basic properties of the dialog box

    Builder.settitle ("xxx");

    Builder.setmessage ("xxx");

    Add corresponding button options

    Builder.setpositivebutton ("OK", null);

    Builder.setnegativebutton ("Cancel", null);

    Create an object of type Alertdialog

    Alertdialog Alertdialog = Builder.create ();

    Show dialog box

    Alertdialog.show ();

    Way two:

    ShowDialog (int id);

    overriding oncreatedialog (int id)

  2. Progress bar Component

    (1) ProgressBar components: Horizontal progress bar

    Setmax (): Set Total progress

    Setprogress (): Set Current progress

    Setsecondaryprogress (): Set second progress

    (2) Seekbar component: can drag horizontal progress bar

    Setonseekbarchangelistener: Setting up drag-and-drop monitoring

    (3) Ratingbar components: Scoring progress bar

    Setnumstars (): Set the total number of stars

    Setrating (): Set the number of stars selected

  3. Date Time class component

    (1) AnalogClock components

    (2) DigitalClock components

    (3) Timepickerdialog Time Selection dialog box

    Get Calendar Object

    Calendar calender = Calender.getinstance ();

    Timepickerdialog Timepickerdialog = new Timepickerdialog (this,new Ontimesetlistener () {

    @Override

    public void Ontimeset (timepicker view, int hourofday, int minute) {

    }

    },calendar.get (Calender.hour), Calendar.get (Calendar.mimute), true);

    Timepickerdialog.show ();

    (4) Datepickerdialog Date selection dialog box

    Datepickerdialog Datepickerdialog = new Datepickerdialog (this,new Ondatesetlistener () {

    @Override

    public void Ondateset (DatePicker view,int year,int monthofyear,int dayofmonth) {

    }

    },0,0,0);

    Datepickerdialog.show ();


Android Learning note-Development components 3

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.