主要练习了自定义样式和主题,继承android系统默认的样式并修改,练习xml定义淡入淡出动画
anim/fade_in.xml
<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="/apk/res/android"android:duration="3000"android:fromAlpha="0.0"android:toAlpha="1.0" />
anim/fade_out.xml
<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="/apk/res/android"android:fromAlpha="1.0" android:toAlpha="0.0"android:duration="3000"/>
values/styles.xml
<?xml version="1.0" encoding="utf-8"?><resources xmlns:android="/apk/res/android"><!-- 自定义动画样式 --><style name='fade' parent="@android:style/Animation.Activity"><item name="android:activityOpenEnterAnimation">@anim/fade_in</item><item name="android:activityOpenExitAnimation">@anim/fade_out</item><item name="android:activityCloseEnterAnimation">@anim/fade_in</item><item name="android:activityCloseExitAnimation">@anim/fade_out</item></style><!-- 自定义动画主题 --><style name="Theme.Tsh" parent="@android:style/Theme.Light.NoTitleBar"><item name="android:windowAnimationStyle">@style/fade</item></style></resources>
MainActivity.java
package com.example.tsh;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.os.Handler;public class MainActivity extends Activity {private Handler handler=new Handler();@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_main);handler.postDelayed(new Runnable() {@Overridepublic void run() {Intent intent=new Intent(MainActivity.this, TwoActivity.class);startActivity(intent);}}, 3000);}}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="/apk/res/android"package="com.example.tsh"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="8"android:targetSdkVersion="21" /><applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="ss" ><activityandroid:name=".MainActivity"android:label="首页"android:theme="@style/Theme.Tsh" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activityandroid:name=".TwoActivity"android:theme="@style/Theme.Tsh" ></activity></application></manifest>