Android Development Study Notes (10) implement a simple opening Interface

Source: Internet
Author: User

Many applications display a welcome page after pressing the mark, and then jump to the main activity function. Now we can implement the following. I mainly referred to a blog on csdn that imitates the weichat opening interface, which is equivalent to a simple version.

Method 1: Use the functions provided by the system.

First, you must create a new class named welcome. java. The main activity is mainactivity. java.

Two functions are used to display the content of R. layout. Start in full screen.

1) getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen,Windowmanager. layoutparams. flag_fullscreen); // remove the status bar

Note:

 
Public void addflags (INT flags) {setflags (flags, flags );}

Therefore, this function can also be written as getwindow (). addflags (windowmanager. layoutparams. flag_fullscreen );

2) requestwindowfeature (window. feature_no_title); // remove the title bar

This function must be written before setcontentview; otherwise, it is invalid.

Opening screen activity, welcome. Java

Package COM. xujin. smarttaskman; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. OS. handler; import android. view. window; import android. view. windowmanager;/** opening welcome animation */public class welcome extends activity {@ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // The welcome screen requestwindowfeature (window. feature_no_title); getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen); setcontentview (R. layout. start); // after a delay of 0.7 seconds, execute the page jump from the run method to new handler (). postdelayed (New runnable () {@ overridepublic void run () {intent = new intent (welcome. this, mainactivity. class); startactivity (intent); welcome. this. finish () ;},700 );}}

Then the most basic XML file

Start. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: Orientation = "vertical"> <imageview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/welcome" Android: Background = "# ffffff" Android: scaletype = "centercrop"/> </linearlayout>

Note that the scaletype here must be centercrop (so that the image overwrites the entire imageview), otherwise the display will be poor.

The above method may cause an instant non-full screen mode error.

Method 2: change the content of androidmainfest. xml.

Set welcome to the activity that is displayed first after clicking the OPEN button. Set them to full screen without a title bar.

<Activity Android: Name = "com. xujin. smarttaskman. welcome "Android: Label =" @ string/app_name "Android: theme =" @ Android: style/theme. notitlebar. fullscreen "> <intent-filter> <action Android: Name =" android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity>

This method does not explicitly use functions, which is easy to understand, and does not show the first method instant non-full screen mode error.

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.