Style and theme in Android: Switch the background image when the Android Application Starts

Source: Internet
Author: User

 

Recently, I have been studying the FM radio source code. After a week of study, I have basically understood the call relationship of the source code and the display of the layout file.

The feeling is that its layout and calling between classes are quite meticulous, but you can digest it slowly. It is distressing that there is still a lot of underlying knowledge not involved,

At present, it is only a step-by-step study, hoping to study thoroughly as soon as possible.

When I learned how to switch the background picture of the FM radio, I felt very interesting. So I finally learned how to observe it step by step. In total

End: The theme attribute of the activity used by the special effect switching technology of the background. Then, after the startup is successful, the custom contentview (View) is called to display

Our images. The special effects of FM radio are as follows:

 

After the initial startup, the page is displayed as follows:

 


 

 

Next, let's start our trip. It's really simple. Just light travel.

 

1. Create a styles. xml file in the values file and add an attribute node:

<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <! -- Style name and the theme of the inherited system --> <style name = "theme. mainactivity" parent = "Android: Theme"> <! -- Whether a title bar is allowed --> <item name = "Android: windownotitle"> true </item> <! -- Prompt background image --> <item name = "Android: windowbackground"> @ drawable/bg_theme </item> <item name = "Android: windowcontentoverlay "> @ null </item> <! -- Whether to allow gloomy background --> <item name = "Android: backgrounddimenabled"> false </item> </style> <! -- Dialog style activity --> <style name = "theme. floatactivity "parent =" Android: style/theme. dialog "> <item name =" Android: windowbackground "> @ drawable/bg_car </item> <item name =" Android: backgrounddimenabled "> false </item> </style> </resources>

 

2. Apply the previously created theme/style in the androidmanifest file.

 

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.feixun.cn" android:versionCode="1" android:versionName="1.0"><application android:icon="@drawable/icon" android:label="@string/app_name"><activity android:name=".MainActivity" android:label="@string/app_name"android:theme="@style/Theme.MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".TestActivityCallBack"></activity><activity android:name=".TestActivityCallBack_2" android:theme="@style/Theme.MainActivity"></activity></application></manifest> 

 

 

Next, we use a program to verify our special effects. When the program starts, it displays "theme. mainactivity" in our custom properties"

The bg_theme image in, after entering the program, displays the bg_car image in our custom layout. Does it look so dazzling. To extend the special effect time, handler can be used to extend the special effect time. The procedure is as follows:

 

  
Importandroid. app. activity; import android. OS. bundle; importandroid. OS. handler; importandroid. OS. message; importandroid. widget. linearlayout; public class mainactivity extends activity {Private Static int wait_for = 1;/** called whenthe activity is first created. * // @ override public void oncreate (bundlesavedinstancestate) {super. oncreate (savedinstancestate); // uses handler to sleep the main thread for a period of time. sendemptymessage (wait_for); setcontentview (R. layout. main);} private handler = new handler () {public voidhandlemessage (Message MSG) {If (MSG. what = wait_for) {try {// The main thread sleeps for a period of time. sleep (5000);} catch (interruptedexception e) {// todo auto-generatedcatch Block E. printstacktrace ();}}}};}

Doesn't it look so trendy? Oh, I feel like it's added to your application .. We are the influx of people.

 

 

Code:Http://download.csdn.net/detail/qinjuning/3807070

 

 
 
 
 
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.