你的位置:首页 > 操作系统

[操作系统][android] 练习样式主题自定义activity切换动画


主要练习了自定义样式和主题,继承android系统默认的样式并修改,练习

anim/fade_in.

<??><alpha ="http://schemas.android.com/apk/res/android"  android:duration="3000"  android:fromAlpha="0.0"  android:toAlpha="1.0" />

anim/fade_out.

<??><alpha ="http://schemas.android.com/apk/res/android"  android:fromAlpha="1.0"   android:toAlpha="0.0"  android:duration="3000"/>

values/styles.

<??><resources ="http://schemas.android.com/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();  @Override  protected void onCreate(Bundle savedInstanceState) {    // TODO Auto-generated method stub    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    handler.postDelayed(new Runnable() {      @Override      public void run() {        Intent intent=new Intent(MainActivity.this, TwoActivity.class);        startActivity(intent);      }    }, 3000);  }}

Manifest.

<??><manifest ="http://schemas.android.com/apk/res/android"  package="com.example.tsh"  android:versionCode="1"  android:versionName="1.0" >  <uses-sdk    android:minSdkVersion="8"    android:targetSdkVersion="21" />  <application    android:allowBackup="true"    android:icon="@drawable/ic_launcher"    android:label="ss" >    <activity      android: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>    <activity      android:name=".TwoActivity"      android:theme="@style/Theme.Tsh" >    </activity>  </application></manifest>