Android利用Theme自定義Activity間的切換動(dòng)畫
大多Android系統(tǒng)默認(rèn)Activity間的動(dòng)畫切換效果為,右邊滑入,左邊滑出;有時(shí)候我們的需求可能是要求所有Activity的切換為淡入淡出的效果,這時(shí)候就可能需要改變一下默認(rèn)的切換風(fēng)格。
下面開始實(shí)現(xiàn):
首先在res文件夾下建立anim文件夾,然后在里面建立fade_in.xml和fade_out.xml兩個(gè)動(dòng)畫資源
fade_in.xml
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:toAlpha="1.0" />
fade_out.xml
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromAlpha="1.0" android:interpolator="@android:anim/accelerate_interpolator" android:toAlpha="0.0" />
然后在values文件夾下的styles.xml中的resources標(biāo)簽內(nèi)寫:
<style name="Anim_fade" parent="android:Theme.NoTitleBar"> <item name="android:windowAnimationStyle">@style/fade</item> </style> <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>
最后一步在AndroidManifest.xml中的Activity的聲明上加入android:theme="@style/Anim_fade"
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.customanimationforactivity" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" > <activity android:name="com.example.customanimationforactivity.MainActivity" android:label="@string/app_name" android:theme="@style/Anim_fade" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".AppActivity" android:theme="@style/Anim_fade" > </activity> </application> </manifest>
貼下Splash Activity的代碼:
package com.example.customanimationforactivity; 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) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); handler.postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(MainActivity.this, AppActivity.class); startActivity(intent); finish(); } }, 1000); } }
源碼下載:http://xiazai.jb51.net/201609/yuanma/CustomAnimation(jb51.net).rar
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android 避免APP啟動(dòng)閃黑屏的解決辦法(Theme和Style)
- Android入門之Style與Theme用法實(shí)例解析
- 基于android樣式與主題(style&theme)的詳解
- Android系統(tǒng)自帶樣式 (android:theme)
- Android中應(yīng)用界面主題Theme使用方法和頁(yè)面定時(shí)跳轉(zhuǎn)應(yīng)用
- Android使用Theme自定義Activity進(jìn)入退出動(dòng)畫的方法
- Android中使用Theme來(lái)解決啟動(dòng)app時(shí)出現(xiàn)的空白屏問(wèn)題
- Android設(shè)置theme中可能遇到的坑
相關(guān)文章
Kotlin示例講解標(biāo)準(zhǔn)函數(shù)with與run和apply的使用
Kotlin的標(biāo)準(zhǔn)函數(shù)是指 Standard.kt 文件中定義的函數(shù),任何Kotlin代碼都可以自由地調(diào)用所有的標(biāo)準(zhǔn)函數(shù)。文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2022-08-08Android實(shí)現(xiàn)Camera2預(yù)覽和拍照效果
這篇文章主要為大家詳細(xì)介紹了Android開發(fā)之一個(gè)類實(shí)現(xiàn)Camera2預(yù)覽和拍照效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10Android音視頻開發(fā)之MediaExtactor使用教程
MediaExtactor在Android音視頻開發(fā)中負(fù)責(zé)提取音視頻信息和數(shù)據(jù)流的功能,可以通過(guò)該類實(shí)現(xiàn)從多媒體文件中剝離得到音頻和視頻的能力。本文將詳細(xì)為大家介紹一下它的使用,感興趣的可以了解一下2022-04-04Android實(shí)現(xiàn)支持進(jìn)度條顯示的短信備份工具類
這篇文章主要介紹了Android實(shí)現(xiàn)支持進(jìn)度條顯示的短信備份工具類,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03獲取Android應(yīng)用專屬緩存存儲(chǔ)目錄的實(shí)例
今天小編就為大家分享一篇獲取Android應(yīng)用專屬緩存存儲(chǔ)目錄的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08Android編程實(shí)現(xiàn)向SD卡寫入數(shù)據(jù)的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)向SD卡寫入數(shù)據(jù)的方法,涉及Android針對(duì)SD卡狀態(tài)判斷,文件及權(quán)限操作等相關(guān)技巧,需要的朋友可以參考下2016-04-04Android 點(diǎn)擊生成二維碼功能實(shí)現(xiàn)代碼
二維碼,我們也稱作QRCode,QR表示quick response即快速響應(yīng),在很多App中我們都能見到二維碼的身影,最常見的莫過(guò)于微信了。接下來(lái)給大家介紹android 點(diǎn)擊生成二維碼功能實(shí)現(xiàn)代碼,需要的朋友參考下吧2017-11-11