解决Android启动显示空白界面的问题,自定义进入软件前的背景图片。

来源:互联网 发布:icmp.dll被java嗲用 编辑:程序博客网 时间:2024/05/01 04:27

Android程序启动时,第一个看的界面并不是我们的指定的第一个Activity界面,而是显示了一个空白的界面,带标题栏的,但是界面什么内容都没有,这个界面只显示不到1秒左右的时间就会切换到我们的第一个Activity界面了,解决办法:在第一个启动的Activity的声明中增加:android:theme="@android:style/Theme.Translucent",具体代码如下(在清单文件中):

</pre><pre name="code" class="html"><activity            android:name=".activity.MainActivity"            android:label="@string/app_name"            android:launchMode="singleTop"            android:screenOrientation="portrait"            android:theme="@android:style/Theme.Translucent" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>
顺着Theme看下去,我想看看它的style怎么写的,这个时候发现了决定背景的那个属性,嘿嘿,这方面真的接触很少,之前我想到的方法

    <style name="Theme.Translucent">        <item name="windowBackground">@color/transparent</item>        <item name="colorBackgroundCacheHint">@null</item>        <item name="windowIsTranslucent">true</item>        <!-- Note that we use the base animation style here (that is no             animations) because we really have no idea how this kind of             activity will be used. -->        <item name="windowAnimationStyle">@style/Animation</item>    </style>
就是这段代码起到了作用
    <!-- Base application theme. -->    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">        <item name="android:windowBackground">@drawable/start_back</item>        <!-- Customize your theme here. -->    </style>


0 0
原创粉丝点击