在做项目的当中,就碰到了这个问题:启动app的时候,会出现一秒左右的白屏或者黑屏;当然,我们肯定会到网上搜索如何解决这个问题,我在这里写一下,我搜到的方法,好处及缺点。
一、设置windowBackground,给启动页设置这个theme
AndroidManifest.xml
<activity android:name=".activity.FirstActivity" android:label="@string/app_name" android:theme="@style/Theme.Start" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
styles.xml
<style name="Theme.Start" parent="android:Theme"> <item name="android:windowBackground">@drawable/splash_bg</item> <item name="android:windowNoTitle">true</item> </style>
这个方法的可行之处,当你的app启动页常年不需要更换的时候,推荐使用这种方法, 简单,快捷,而且activity的切换动画也是有效的,但是如果当你的app启动页会不定时更换的时候,这个方法就不行了。
二、设置 android:windowIsTranslucent
<style name="Theme.Start" parent="android:Theme"> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> </style>
当设置这个方法之后,app第一个启动页,会按系统默认的动画,打开、退出页面
<style name="Theme.Start" parent="android:Theme"> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowAnimationStyle">@style/AnimationActivity</item> </style>
不管是否设置android:windowAnimationStyle,他不会按着这个方法来,所以我们可以去掉这一行,那么问题来了,当设置android:windowIsTranslucent后,动画就会失效,怎么办呢,我在网上找了下,也就那么一两种方法,还不是我想要的效果,于是,再思考之后,发现,我直接用代码设置切换也是可行的呀,说做就做,既然失效的是app的启动页,那么我就给启动页设置切换动画。
核心代码:
Intent intent = new Intent(FirstActivity.this, LoginActivity.class); startActivity(intent); this.finish(); overridePendingTransition(R.anim.anim_right_in,R.anim.anim_left_out);
给启动页加入overridePendingTransition之后,切换到另一页的动画就出来了。
目前,就已经达到我想要的效果了,点开app,调用系统默认打开动画,进去启动页,延迟两秒,通过overridePendingTransition,自定义动画来切换到下一页。
那么,有的人可能就有疑惑,如果我非要自定义启动页进入的动画呢?
<style name="Theme.Start" parent="android:Theme"> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowAnimationStyle">@style/animation_translucent_translate</item> </style> <style name="animation_translucent_translate" parent="@android:style/Animation.Translucent"> <item name="android:windowEnterAnimation">@anim/anim_right_in</item> <item name="android:windowExitAnimation">@anim/anim_left_out</item> </style>
这样就可以达到我们想要的效果,调用自定义开始动画,overridePendingTransition自定义切换动画,android:windowExitAnimation在我的小米3手机上会失效,可以无视他,并不起什么作用。
贴出我自己想要的效果的代码:
AndroidManifest.xml 里面一个设置
<activity android:name=".activity.FirstActivity" android:label="@string/app_name" android:theme="@style/Theme.Start" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
styles.xml里面有一个主题
<style name="Theme.Start" parent="android:Theme"> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> </style>
FirstActivity.java 里面一个方法
Intent intent = new Intent(FirstActivity.this, LoginActivity.class); startActivity(intent); this.finish(); overridePendingTransition(R.anim.anim_right_in,R.anim.anim_left_out);
相关推荐
介绍:用ViewDragHelper实现的activity切换动画。运行效果:使用说明: 你可以将这个库当成view来用:将DraggerView添加到root layout,并且在里面加入两个layout。 android:layout_width="match_parent" ...
这种问题一般是因为一个Activity启动之后在显示视图之间时间太长导致的。 1、优化方式可以通过精简layout文件... ”android:windowIsTranslucent”>true</item> 将默认的窗口背景设置为透明色,这样就不会出现黑屏了
<item name="android:windowIsTranslucent">true</item> <item name="android:windowSoftInputMode">adjustNothing <item name="android:windowNoTitle">true</item> </style> -----------...
和 Activity 的 theme 并无关系 不影响 activity 的生命周期 只需继承 BaseActivity isSupportSwipeBack 唯一 API 方法,简单实用 无需设置 <item name="android:windowIsTranslucent">true 支持 Dialog 的滑动返回
android滑动返回效果,只能向左滑动、向右滑动、向下滑动返回 导入源码后需要拷入android-...3、在你的Activity的Theme中添加<item name="android:windowIsTranslucent">true</item> 相关事宜,源码跑下就知道了~
Note: activity of manifest need to override the configured theme: android: windowIsTranslucent, otherwise slide open the background is black. <style name="ActivityTheme" parent="Theme.AppCompat....
本文实例讲述了Android编程中activity启动时出现白屏、黑屏问题的解决方法。分享给大家供大家参考,具体如下: 默认情况下 activity 启动的时候先把屏幕刷成白色,再绘制界面,绘制界面或多或少有点延迟,这段时间中...
使用方法:下载后解压,并在你的项目里导入module; 写一个 BaseActivity 继承 SwipeBackActivity: public class BaseActivity extends SwipeBackActivity {...<item name="android:windowIsTranslucent">true</item>
要原因是主体样式设置的问题:这里把appTheme设置... <item name=android:windowIsTranslucent>false <item name=Android:windowNoTitle>true 出现其他的短暂显示桌面问题,都可以使用上面的方式去解决。 以上所述是小
图片较大 加载会慢一些 耐心等待Demo Activity1Demo Activity2使用说明:Activity滑动返回<!--设置主题属性--> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> name=...
将app的主题设置加入 <item name="android:windowIsTranslucent">true --这样主题就可以使透明的,不能用默认的主题;使用默认背景就是黑屏了,这个属性就是设置防止黑屏的。 关于阻止黑屏可查看:...
”android:windowBackground”>@color/translucent_background</item><item name=”android:windowIsTranslucent”>true</item></style> 在该文件夹下在创建文件colors.xml 代码如下:<?xml version=“1.0″...
Tips.6如需动态支持横竖屏切换(比如APP中有“支持横屏”开关),屏幕方向需指定为behind跟随栈底Activity方向,同时在onCreate中进行判断,若不支持横竖屏切换则锁定屏幕方向(因为经测试SDK21中behind无效)。
该依赖库是用于Android开发中滑动返回使用,下载后,导入项目,...使用后,出现滑动时,背景为黑色,需要让该Activity的theme继承自自定义style,并在该style中添加<item name="android:windowIsTranslucent">true即可
<item name=android:windowIsTranslucent>true </style> 2.自定义侧边阴影视图 class SlideBackView extends View { private Paint mBgPaint, mShadowPaint; private RectF mBgRectF, mShadowRectF; ...