• android开发 解决启动页空白或黑屏问题


    遇到的情况:

    app启动时进入启动页时出现白屏页,然后大概一秒之后就出现了背景图片。

    原因:app启动时加载的是windows背景,之后再加载布局文件的,所以开始的黑屏/白屏就是windows的背景颜色,因此我们只要在启动页设置windows背景颜色就好了,那么在哪里设置呢?  就是theme里面。

    解决办法:参考:【Android Drawable 那些不为人知的高效用法

    Android 启动APP时黑屏白屏的三个解决方案

    首先看之前的布局文件xml写法

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <ImageView 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:background="@drawable/bg_app_welcome_1"/>
        <LinearLayout 
            android:id="@+id/v_prepare_tips"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:orientation="horizontal"
            android:visibility="gone">
            <TextView 
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:textColor="#007ed2"
                android:text="首次安装正在准备数据"/>
            <ProgressBar 
                android:layout_width="20dp"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"/>
        </LinearLayout>
        
    
    </RelativeLayout>

    =========================================================

    优化之后的:

    <!-- 只是将根元素的背景去掉了 -->
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <LinearLayout 
            android:id="@+id/v_prepare_tips"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:orientation="horizontal"
            android:visibility="gone">
            <TextView 
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:textColor="#007ed2"
                android:text="首次安装正在准备数据"/>
            <ProgressBar 
                android:layout_width="20dp"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"/>
        </LinearLayout>
    </RelativeLayout>

    设置style.xml

        <style  name="AppStartingBg"  parent="@android:style/Theme.Holo.Light.NoActionBar" >  
            <item name="android:windowBackground">@drawable/bg_appstarting</item>  
        </style> 
    bg_appstarting.xml
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >   
          <item >  
             <bitmap android:src="@drawable/bg_app_welcome_1" android:gravity="fill" /> 
        </item>
    </layer-list>

    再在manifest.xml文件中添加该ancivity的theme

    <activity
                android:name="com.client.activity.AppStartingActivity"
                android:icon="@drawable/ic_logo_2"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@style/AppStartingBg" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

    大功告成!

  • 相关阅读:
    证书介绍
    Hadoop生态上几个技术的关系与区别:hive、pig、hbase 关系与区别
    Hive安装与配置详解
    技术学习内容
    死锁,更新锁,共享锁,排它锁,意向锁,乐观锁,悲观锁等名词解释及案例详解
    死锁语句
    SQL Server 锁表、查询被锁表、解锁相关语句
    Psi Probe 安装及使用说明
    PowerDesigner使用教程
    Python -面向对象(一 基本概念)
  • 原文地址:https://www.cnblogs.com/feijian/p/4743154.html
Copyright © 2020-2023  润新知