Starting today based on the basics of prior learning Android, combat it to achieve a simple feature of Android phone defender
This article address: http://www.cnblogs.com/wuyudong/p/5899283.html, reprint please indicate source address.
The main functions of mobile phone defender are as follows:
The splash page of the mobile page is initially as follows:
Splash Layout
The corresponding code is in the layout file Activity_splash.xml file:
<Relativelayoutxmlns: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= "@drawable/launcher_bg"Tools:context=". Splashactivity " > <TextViewAndroid:id= "@+id/tv_version_name"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centerinparent= "true"Android:shadowcolor= "#f00"ANDROID:SHADOWDX= "1"Android:shadowdy= "1"Android:shadowradius= "1"Android:text= "Version name"Android:textcolor= "#fff"android:textsize= "16SP" /> <ProgressBarAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"Android:layout_below= "@+id/tv_version_name" /></Relativelayout>
Activity go head Operation & keep high version theme
Next remove the title of the head display: Mobilesafe
Method 1: Add the following code to the specified activity:
Public class extends Activity { @Override protectedvoid onCreate (Bundle savedinstancestate) { Super . OnCreate (savedinstancestate); // Remove the current actinity tittle requestwindowfeature (window.feature_no_title); Setcontentview (R.layout.activity_splash); } }
But every activity needs to be configured, and it's a bit cumbersome.
Method 2: Modify the Android:theme= "@style/apptheme" in the manifest file to: Android:theme= "@android: Style/theme.light.notitlebar
Can achieve the effect, but the other styles of the theme have also changed, in order to be compatible with these two aspects, modify Styles.xml, add the following code:
<!--application theme. - <stylename= "Apptheme"Parent= "Appbasetheme"> <!--maintain a high version of the style theme while going to the head - <!--All customizations, that is, specific to a particular api-level can go. - <item name= "Android:windownotitle">true</ Item > </style>
Get
Get the version name and show
Public classSplashactivityextendsActivity {PrivateTextView Tv_version_name; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //Remove the current actinity tittle//requestwindowfeature (window.feature_no_title);Setcontentview (R.layout.activity_splash); //initializing the UIInitui (); //Initializing DataInitData (); } /*** Get Data method*/ Private voidInitData () {//Apply version nameTv_version_name.settext ("Version name:" +getversionname ()); } /*** Get version name: In the manifest file * *@returnapplication version name returns NULL for an exception*/ PrivateString Getversionname () {//1. Manager Object PackagemanagerPackagemanager pm =Getpackagemanager (); //2. From the manager object of the package, get the basic information for the specified package name (version name, version number) Try{packageinfo PackageInfo= Pm.getpackageinfo (Getpackagename (), 0); //3. Get the version name returnPackageinfo.versionname; } Catch(Exception e) {e.printstacktrace (); } return NULL; } /*** Initialize UI method Alt+shift+j*/ Private voidInitui () {tv_version_name=(TextView) Findviewbyid (r.id.tv_version_name); }}
When you are finished, run the project
Android Project Combat-Mobile Defender (realize Splash)