Android Interface Programming--Date Time component (V)

Source: Internet
Author: User
Tags xml attribute


Android Interface Programming--Date Time component
2.6 Date Time component 2.6.1 Textclock

Displays the system date and time as text, customizable display format, and is a new feature provided by Android4.2 ( corresponding to API level 17).

There are two ways to format Textclock:

1. In the hour mode:

Property:Android:format24hour

Method:Set Format24hour (charsequence)

2. In the hour mode:

Property:Android:format12hour

Method:Set Format12hour (charsequence)

The following is a case 2.6-1, explaining The use of textclock, the implementation of the effect 2.6-1

Figure 2.6-1




2.6.2 AnalogClock

The AnalogClock control displays the analog clock . It inherits the view component and overrides the OnDraw method on the basis of the view component , in onDraw The method implements the drawing of the analog clock, but draws the hour and minute hands without the second hand.

Table 2.6-1 lists the XML attributes supported by AnalogClock .

Table 2.6-1analogclock supported XML attribute descriptions

XML Properties

Note

Android:dial

Set up a picture of the use of the analogue dial

Android:hand_hour

Set the picture to be used when simulating the dial hour

Android:hand_minute

Set up a picture of the analog dial minute hand

The following is a case 2.6-2, explaining The basic usage of anlogclock, the implementation of the effect 2.6-2

Figure 2.6-2


2.6.3 DatePicker and timepicker

DatePicker and timepicker are Android -provided controls for selecting a time and selecting a date.

They are all inherited from framelayout, and they are relatively simple to use.

Using the DatePicker and timepicker controls helps ensure that a user chooses a time or date that is valid and formatted correctly.

Timepicker is used to select each part of the time (hours, minutes, mornings / afternoons).

DatePicker is used to select each part of the date (month, day, year).

2.6-3 as shown:

Figure 2.6-3

Table 2.6-2 lists the XML attributes supported by DatePicker .

Table 2.6-2 XML attribute Descriptions supported by DatePicker

XML Properties

Note

Android:calendarviewshown

Whether to display the calendarview component

Android:spinnersshown

Whether to display the Spinner component

Android:endyear

Whether to allow the last year to be selected

Android:startyear

Whether to allow selection of the first year

Android:maxdate

Displays the maximum date for this calendar view in mm/dd/yyyy format

Android:mindate

Displays the minimum date for this calendar view in mm/dd/yyyy format

The following is a case 2.6-3, explaining the basic usage of anlogclock , the implementation of the effect 2.6-3

 

Figure 2.6-3





public class Pickeractivity extends appcompatactivity {private int year;    private int month;    private int day;    private int hour;    private int minute;    Private DatePicker DatePicker;    Private Timepicker Timepicker;  @OverridedatePicker. Init (year, month, day, new Datepicker.ondatechangedlistener () {@Override public                void Ondatechanged (DatePicker arg0, int year, int month, Int. day) {PickerActivity.this.year = year; PickerActivity.this.month = month;                PickerActivity.this.day = day;            Displays the current time and date showdate (year, month, day, hour, minute);        }        }); Specifies event listener Timepicker.setontimechangedlistener (new Timepicker.ontimechangedlistener () {@Ove for Timerpicker Rride public void ontimechanged (Timepicker arg0, int hour, int minute) {PickerActivity.this.hou                R = Hour;            PickerActivity.this.minute = minute;        }        }); Showdate (yEar,month,day,hour,minute); } protected void Showdate (int year, Int. month, int day, int hour,int minute) {EditText text = (EditText) findvi        Ewbyid (r.id.etshowdate);    Text.settext ("Selected date and Time:" + year + "years" + (month+1) + "Month" + Day + "days" + hour + "+ minute+"); }}

2.6.5 CalendarView

is a calendar component that is used to display and select dates. The range supported by the calendar is configurable. The user can select a date, or you can select the desired date by touching scroll.

Table 2.6-3 lists the XML attributes supported by CalendarView .

Table 2.6-3 XML attribute Descriptions supported by CalendarView

XML Properties

Method

Note

Android:datetextappearance

Setdatetextappearance (INT)

Set the style of the Calendar control date text

Android:maxdate

Setmaxdate (Long)

The minimum date displayed in this calendar view in mm/dd/yyyy format

Android:mindate

Setmindate (Long)

The maximum date displayed in this calendar view in mm/dd/yyyy format

Android:firstdayofweek

Setfirstdayofweek(INT)

Set the first day of the week for the calendar

Android:shownweekcount

Set Shownweekcount (INT)

Set the calendar to show a total of several weeks

Android:selectedweekbackgroundcolor

Setselectedweekbackgroundcolor (INT)

Sets the background color of the selected week

Android:focusedmonthdatecolor

Setfocusedmonthdatecolor

Sets the color of the text for the focus month

Android:weekseparatorlinecolor

Setweekseparatorlinecolor (INT)

Set the color of the week split line

Android:unfocusedmonthdatecolor

Setunfocusedmonthdatecolor (INT)

Sets the color of text for unselected months

The following is a case 2.6-4, explaining the basic usage of calendarview, the implementation of the effect 2.6-4.

Figure 2.6-4



public class Calendarviewactivity extends Appcompatactivity {private CalendarView CV;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_calendar_view);        cv= (CalendarView) Findviewbyid (R.id.calenddarview);    Initcalendarview (); The private void Initcalendarview () {//Adds event listener Cv.setondatechangelistener for the CalendarView component's date Change event (new Calenda Rview.ondatechangelistener () {@Override public void Onselecteddaychange (CalendarView view, int year                , int month, int dayofmonth) {//Use Toast to display the date selected by the user                        Toast.maketext (Calendarviewactivity.this, "Ticket purchase Date:" + year + "years" + month + "Month" + DayOfMonth + "Day"            , Toast.length_short). Show ();    }        }); }}

Case Key points:

Get the date selected by the user by setting the date listener Ondatechangelistener for the CalendarView object and the replication callback method Onselecteddaychange ()




The peak of the cupola 20160711


Android Interface Programming--Date Time component (V)

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.