The Application Start interface is a simple countdown to the dialog, and the interface countdown to the dialog

Source: Internet
Author: User

The Application Start interface is a simple countdown to the dialog, and the interface countdown to the dialog

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#FF85C17E"    tools:context="com.example.lesson7_2_id19_dialog.MainActivity"></RelativeLayout>

Dialog_start.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:background="@mipmap/timg"> 6  7     <TextView 8         android:id="@+id/tv_time" 9         android:gravity="center"10         android:background="@drawable/oval"11         android:layout_width="wrap_content"12         android:layout_height="wrap_content"13         android:text="3s"14         android:layout_alignParentRight="true"15         android:layout_margin="20dp"/>16 17 </RelativeLayout>

Oval. xml custom circle under drawable

 1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android" 3     android:shape="oval"> 4     <padding 5         android:bottom="5dp" 6         android:left="5dp" 7         android:right="5dp" 8         android:top="5dp" /> 9     <stroke10         android:width="1dp"11         android:color="#7bf0f2" />12 </shape>

Java code:

1 package com. example. lesson7_2_id19_dialog; 2 3 import android. app. dialog; 4 import android. content. context; 5 import android. OS. bundle; 6 import android. OS. countDownTimer; 7 import android. support. annotation. nonNull; 8 import android. widget. textView; 9 10/** 11 * Created by Administrator on 0008.12 */13 14 public class StartDialog extends Dialog {15 // inherit the dialog override constructor 16 public StartDialog (@ NonNull Context context) {17 super (context, R. style. dialogStyle); 18 19} 20 21 TextView TV _time; 22 23 @ Override24 protected void onCreate (Bundle savedInstanceState) {25 super. onCreate (savedInstanceState); 26 setContentView (R. layout. dialog_start); 27 // set whether to disable the current control 28 setCancelable (false); 29 // find the TV _time control 30 TV _time = (TextView) findViewById (R. id. TV _time); 31 new DownTimer (). start (); 32} 33 34 // inherit from the CountDownTimer class 35 class DownTimer extends CountDownTimer {36 37 public DownTimer () {38 // set the time to 4 seconds 39 super (4000,100 0 ); 40} 41 // override CountDownTimer's two Methods 42 @ Override43 public void onTick (long millisUntilFinished) {44 TV _time.setText (millisUntilFinished/1000 + "s "); 45} 46 47 @ Override48 public void onFinish () {49 StartDialog. this. dismiss (); 50 51} 52 53} 54}
1 package com. example. lesson7_2_id19_dialog; 2 3 import android. content. dialogInterface; 4 import android. OS. bundle; 5 import android. support. v7.app. appCompatActivity; 6 import android. widget. toast; 7 8 public class MainActivity extends AppCompatActivity {9 10 @ Override11 protected void onCreate (Bundle savedInstanceState) {12 super. onCreate (savedInstanceState); 13 setContentView (R. layout. activity_main); 14 StartDialog dialog = new StartDialog (this); 15 dialog. show (); 16 dialog. setOnDismissListener (new DialogInterface. onDismissListener () {17 @ Override18 public void onDismiss (DialogInterface dialog) {19 Toast. makeText (MainActivity. this, "application start page closed", Toast. LENGTH_SHORT ). show (); 20} 21}); 22} 23}

 

Related Article

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.