`
汪洋00700
  • 浏览: 23182 次
  • 性别: Icon_minigender_1
  • 来自: 常德
社区版块
存档分类

android:windowIsTranslucent 引起activity切换动画无效解决方案

 
阅读更多

在做项目的当中,就碰到了这个问题:启动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);

 

 

 

1
0
分享到:
评论
1 楼 汪洋00700 2016-09-01  
 

相关推荐

    Dragger-用ViewDragHelper实现的activity切换动画。.zip

    介绍:用ViewDragHelper实现的activity切换动画。运行效果:使用说明: 你可以将这个库当成view来用:将DraggerView添加到root layout,并且在里面加入两个layout。  android:layout_width="match_parent"  ...

    Android界面切换出现短暂黑屏的解决方法

    这种问题一般是因为一个Activity启动之后在显示视图之间时间太长导致的。 1、优化方式可以通过精简layout文件... ”android:windowIsTranslucent”&gt;true&lt;/item&gt; 将默认的窗口背景设置为透明色,这样就不会出现黑屏了

    MyFileChooser.rar

    &lt;item name="android:windowIsTranslucent"&gt;true&lt;/item&gt;  &lt;item name="android:windowSoftInputMode"&gt;adjustNothing  &lt;item name="android:windowNoTitle"&gt;true&lt;/item&gt; &lt;/style&gt; -----------...

    滑动返回Activity(带阴影)

    和 Activity 的 theme 并无关系 不影响 activity 的生命周期 只需继承 BaseActivity isSupportSwipeBack 唯一 API 方法,简单实用 无需设置 &lt;item name="android:windowIsTranslucent"&gt;true 支持 Dialog 的滑动返回

    SwipBackLayoutLibrary

    android滑动返回效果,只能向左滑动、向右滑动、向下滑动返回 导入源码后需要拷入android-...3、在你的Activity的Theme中添加&lt;item name="android:windowIsTranslucent"&gt;true&lt;/item&gt; 相关事宜,源码跑下就知道了~

    可以滑动页面的项目

    Note: activity of manifest need to override the configured theme: android: windowIsTranslucent, otherwise slide open the background is black. &lt;style name="ActivityTheme" parent="Theme.AppCompat....

    Android编程中activity启动时出现白屏、黑屏问题的解决方法

    本文实例讲述了Android编程中activity启动时出现白屏、黑屏问题的解决方法。分享给大家供大家参考,具体如下: 默认情况下 activity 启动的时候先把屏幕刷成白色,再绘制界面,绘制界面或多或少有点延迟,这段时间中...

    Android 右滑返回资源

    使用方法:下载后解压,并在你的项目里导入module; 写一个 BaseActivity 继承 SwipeBackActivity: public class BaseActivity extends SwipeBackActivity {...&lt;item name="android:windowIsTranslucent"&gt;true&lt;/item&gt;

    Android开发中调用系统相册上传图片到服务器OPPO等部分手机上出现短暂的显示桌面问题的解决方法

    要原因是主体样式设置的问题:这里把appTheme设置... &lt;item name=android:windowIsTranslucent&gt;false &lt;item name=Android:windowNoTitle&gt;true 出现其他的短暂显示桌面问题,都可以使用上面的方式去解决。 以上所述是小

    KugouLayout-.zip

    图片较大 加载会慢一些 耐心等待Demo Activity1Demo Activity2使用说明:Activity滑动返回&lt;!--设置主题属性--&gt; &lt;style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"&gt;   name=...

    AndroidSwipeBack滑动返回

    将app的主题设置加入 &lt;item name="android:windowIsTranslucent"&gt;true --这样主题就可以使透明的,不能用默认的主题;使用默认背景就是黑屏了,这个属性就是设置防止黑屏的。 关于阻止黑屏可查看:...

    Activity透明/半透明效果的设置transparent(两种实现方法)

    ”android:windowBackground”&gt;@color/translucent_background&lt;/item&gt;&lt;item name=”android:windowIsTranslucent”&gt;true&lt;/item&gt;&lt;/style&gt; 在该文件夹下在创建文件colors.xml 代码如下:&lt;?xml version=“1.0″...

    swipeback-Android侧滑返回分析和实现(不高仿微信).zip

    Tips.6如需动态支持横竖屏切换(比如APP中有“支持横屏”开关),屏幕方向需指定为behind跟随栈底Activity方向,同时在onCreate中进行判断,若不支持横竖屏切换则锁定屏幕方向(因为经测试SDK21中behind无效)。

    SwipeBackLib依赖库

    该依赖库是用于Android开发中滑动返回使用,下载后,导入项目,...使用后,出现滑动时,背景为黑色,需要让该Activity的theme继承自自定义style,并在该style中添加&lt;item name="android:windowIsTranslucent"&gt;true即可

    Android 侧边滑动关闭Activity的示例代码

    &lt;item name=android:windowIsTranslucent&gt;true &lt;/style&gt; 2.自定义侧边阴影视图 class SlideBackView extends View { private Paint mBgPaint, mShadowPaint; private RectF mBgRectF, mShadowRectF; ...

Global site tag (gtag.js) - Google Analytics