首页 > 移动平台 > 详细

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

时间:2016-07-21 23:45:18      阅读:237      评论:0      收藏:0      [点我收藏+]

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

anim/fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/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="http://schemas.android.com/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="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.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="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>

 

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

原文:http://www.cnblogs.com/taoshihan/p/5693487.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!