最近的一球扬名APP出现过实况足球2018白屏闪退,安卓手机的,怎么办,在线等。

Android 启动APP时黑屏白屏的三个解决方案
你会很奇怪,为什么有些app启动时,会出现一会儿的黑屏或者白屏才进入Activity的界面显示,但是有些app却不会如QQ手机端,的确这里要做处理一下。这里先了解一下为什么会出现这样的现象,其实很简单,简历一个简单的例子就可以理解了。
其实,黑屏或者白屏这里并不是不正常,而是还没加载到布局文件,就已经显示了window窗口背景,黑屏白屏就是window窗口背景。代码如下,可以自己写个小demo就理解了。
protected void onCreate(Bundle savedInstanceState) {
& & super.onCreate(savedInstanceState);
& & // 注意:添加3秒睡眠,以确保黑屏一会儿的效果明显,在项目应用要去掉这3秒睡眠
& & & & Thread.sleep(3000);
& & } catch (InterruptedException e) {
& & & & e.printStackTrace();
& & // 在这里之前,黑屏或者白屏都是window的背景颜色,是窗口背景,还没到界面的布局呢,要执行setContentView后才显示布局
& & setContentView(R.layout.activity_launcher);
那window窗口背景在那里提供呢?在提供theme里面,如下提供的是白色背景,那就是启动时白屏一会儿的颜色设置。
&!-- Application theme. --&
&style name=&AppTheme& parent=&AppBaseTheme&&
& & &item name=&android:windowNoTitle&&true&/item&
& & &item name=&android:windowBackground&&@color/white&/item&
& & &!-- All customizations that are NOT specific to a particular API-level can go here. --&
所以,在theme设置windowBackground就可以解决启动时白屏黑屏一会儿了,下面提供三种解决方案:
一、提供.png背景图
提供背景图是解决的一个方法,但是要适配各种屏幕,提供很多张图片。除非图片非常复杂只能用背景图了就用这种方法吧,否则个人不建议。
二、提供.9.png(NinePatch)背景图片
如果图片不是很复杂,可以做成NinePatch图片,那就直接制作NinePatch图片,提供一张就可以适配任何手机,何乐而不为呢。
三、使用Layout-list制作背景图片
如果可以使用这种方式,推荐使用这种Layout-list制作背景图片。前2种都是使用图片占用内存啊,使用Layout-list比较省内存,做出app也不会说因为图片多体积变大吧。
&下面给出代码。
LaunchActivity为启动界面停留3秒后跳转到主页面MainActivity,为了达到显示黑屏白屏的效果更明显,在setContentView之前线程睡眠3秒。
public class LauncherActivity extends Activity {
& & public final int MSG_FINISH_LAUNCHERACTIVITY = 500;
& & public Handler mHandler = new Handler(){
& & & & public void handleMessage(Message msg) {
& & & & & & switch (msg.what) {
& & & & & & case MSG_FINISH_LAUNCHERACTIVITY:
& & & & & & & & //跳转到MainActivity,并结束当前的LauncherActivity
& & & & & & & & Intent intent = new Intent(LauncherActivity.this, MainActivity.class);
& & & & & & & & startActivity(intent);
& & & & & & & & finish();
& & & & & & & &
& & & & & & default:
& & & & & & & &
& & & & & & }
& & & & };
& & @Override
& & protected void onCreate(Bundle savedInstanceState) {
& & & & super.onCreate(savedInstanceState);
& & & & // 不显示的标题栏,保证windowBackground和界面activity_main的大小一样,显示在屏幕不会有错位(去掉这一行试试就知道效果了)
& & & & getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
& & & & // 注意:添加3秒睡眠,以确保黑屏一会儿的效果明显,在项目应用要去掉这3秒睡眠
& & & & try {
& & & & & & Thread.sleep(3000);
& & & & } catch (InterruptedException e) {
& & & & & & e.printStackTrace();
& & & & setContentView(R.layout.activity_launcher);
& & & & // 停留3秒后发送消息,跳转到MainActivity
& & & & mHandler.sendEmptyMessageDelayed(MSG_FINISH_LAUNCHERACTIVITY, 3000);
activity_launcher.xml布局文件,很简单,要记住这里的LinearLayout使用的背景是layout_list_start_pic,跟主题theme使用一样的背景,这样就消除了背景不一样的效果。这里要自己试试才知道这样做的好处和效果。
&LinearLayout xmlns:android=&https://schemas.android.com/apk/res/android&
& & xmlns:tools=&https://schemas.android.com/tools&
& & android:layout_width=&fill_parent&
& & android:layout_height=&fill_parent&
& & android:background=&@drawable/layout_list_start_pic& &
& & &TextView
& & & & android:layout_width=&wrap_content&
& & & & android:layout_height=&wrap_content&
& & & & android:textColor=&#ffffff&
& & & & android:text=&@string/hello_world& /&
&/LinearLayout&
Manifest.xml,这里注意application使用的theme是AppTheme,而LauncherActivity使用的主题是StartAppTheme。这样做的效果是只要LauncherActivity使用StartAppTheme主题,其他Activity都是用AppTheme主题哦。
&?xml version=&1.0& encoding=&utf-8&?&
&manifest xmlns:android=&https://schemas.android.com/apk/res/android&
& & package=&com.example.launcheractivity&
& & android:versionCode=&1&
& & android:versionName=&1.0& &
& & &uses-sdk
& & & & android:minSdkVersion=&8&
& & & & android:targetSdkVersion=&18& /&
& & &application
& & & & android:allowBackup=&true&
& & & & android:icon=&@drawable/ic_launcher&
& & & & android:label=&@string/app_name&
& & & & android:theme=&@style/AppTheme& &
& & & & &activity
& & & & & & android:name=&.LauncherActivity&
& & & & & & android:label=&@string/app_name&
& & & & & & android:theme=&@style/StartAppTheme& &
& & & & & & &intent-filter&
& & & & & & & & &action android:name=&android.intent.action.MAIN& /&
& & & & & & & & &category android:name=&android.intent.category.LAUNCHER& /&
& & & & & & &/intent-filter&
& & & & &/activity&
& & & & &activity android:name=&.MainActivity&&&/activity&
& & &/application&
&/manifest&
styles.xml,2个主题设置
&resources xmlns:android=&https://schemas.android.com/apk/res/android&&
& & & & Base application theme, dependent on API level. This theme is replaced
& & & & by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
& & &style name=&AppBaseTheme& parent=&android:Theme.Light.NoTitleBar&&
& & & & &!--
& & & & & & Theme customizations available in newer API levels can go in
& & & & & & res/values-vXX/styles.xml, while customizations related to
& & & & & & backward-compatibility can go here.
& & & & --&
& & &/style&
& & &!-- Application theme. --&
& & &style name=&AppTheme& parent=&AppBaseTheme&&
& & & & &item name=&android:windowNoTitle&&true&/item&
& & & & &item name=&android:windowBackground&&@color/white&/item&
& & & & &!-- All customizations that are NOT specific to a particular API-level can go here. --&
& & &/style&
& & &style name=&StartAppTheme& parent=&AppBaseTheme&&
& & & & &item name=&android:windowNoTitle&&true&/item&
& & & & &item name=&android:windowBackground&&@drawable/layout_list_start_pic&/item&
& & & & &!-- All customizations that are NOT specific to a particular API-level can go here. --&
& & &/style&
&/resources&
layout_list_start_pic.xml 启动页面使用这个作为背景图片
&?xml version=&1.0& encoding=&utf-8&?&
&layer-list xmlns:android=&https://schemas.android.com/apk/res/android& &
& & &!-- 设置整个屏幕背景为白色 --&
& & &item &
& & & & &color android:color=&@color/white&/&
& & &/item&
& & &!-- 中间logo --&
& & &item &
& & & & &bitmap
& & & & & & android:gravity=&center&
& & & & & & android:src=&@drawable/ic_launcher& /&
& & &/item&
& & &!-- 底部图表 --&
& & &item android:bottom=&10dp&&
& & & & &bitmap
& & & & & & android:gravity=&bottom|center_horizontal&
& & & & & & android:src=&@drawable/copyright& /&
& & &/item&
&/layer-list&最近的一球扬名APP出现过白屏,安卓手机的,怎么办,在线等。_百度知道
最近的一球扬名APP出现过白屏,安卓手机的,怎么办,在线等。
我有更好的答案
你卸载后重 新下载试下。
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。您访问的页面不见了!Android手机淘宝启动页(Splash)是如何实现的? - 知乎有问题,上知乎。知乎作为中文互联网最大的知识分享平台,以「知识连接一切」为愿景,致力于构建一个人人都可以便捷接入的知识分享网络,让人们便捷地与世界分享知识、经验和见解,发现更大的世界。199被浏览<strong class="NumberBoard-itemValue" title="1分享邀请回答schemas.android.com/apk/res/android"&
&bitmap android:gravity="fill" android:src="@drawable/white" /&
&bitmap android:gravity="center" android:src="@drawable/splash" /&
&bitmap android:gravity="bottom|center" android:src="@drawable/splash_bottom" /&
&/item&&/layer-list& -EOF-2512 条评论分享收藏感谢收起&style name="customBackground" parent="@android:style/Theme.Holo.Light"&
&item name="android:windowBackground"&@drawable/start_app&/item&
&item name="android:windowNoTitle"&true&/item&
1511 条评论分享收藏感谢收起android应用程序启动时短暂白屏或者黑屏的解决处理方案
最近在研究使用app的过程中发现有的app首次启动的时候会有短暂的白屏,而有些app则不会出现这样的情况.起初我以为是手机的问题.但是当我换了几个手机进行测试的时候仍然会出现这样的状况.当然出现白屏这样的效果肯定是不会给用户行云流水般的感觉了,接下来我们就来着手解决这样的问题.
转载请标明出处:http://blog.csdn.net/unreliable_narrator?viewmode=contents
老规矩,文字的描述可能略显苍白,我们先来看看解决问题前后的效果对比.
处理前效果,我们可以明显的看到有短暂的白屏.
处理后效果:可以明显的看到基本解决了白屏的问题.
猜想可能是由于先加载窗体再加载activity的布局才引起这样的问题.
解决的方式方式有两种.
一种是自己定义theme,在values文件夹下面找到styles文件自己创建一个主题将background属性设置为我们需要的背景图片,然后在清单文件中设置启动的activity去使用该主题即可.
&resources&
&style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"&
&!-- Customize your theme here. --&
&item name="colorPrimary"&@color/colorPrimary&/item&
&item name="colorPrimaryDark"&@color/colorPrimaryDark&/item&
&item name="colorAccent"&@color/colorAccent&/item&
&style name="AppThemeTwo" parent="Theme.AppCompat.NoActionBar"&
&item name="android:windowBackground"&@android:color/holo_red_light&/item&
&!-- Customize your theme here. --&
&item name="colorPrimary"&@color/colorPrimary&/item&
&item name="colorPrimaryDark"&@color/colorPrimaryDark&/item&
&item name="colorAccent"&@color/colorAccent&/item&
&/resources&
&?xml version="1.0" encoding="utf-8"?&
package="com.dapeng.laucherdemo"
xmlns:android="http://schemas.android.com/apk/res/android"&
&application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"&
android:name=".MainActivity"
android:theme="@style/AppThemeTwo"
&intent-filter&
&action android:name="android.intent.action.MAIN"/&
&category android:name="android.intent.category.LAUNCHER"/&
&/intent-filter&
&/activity&
&/application&
&/manifest&
第二种是直接将窗体的背景颜色设置为透明的.方法和上面的类似,
&resources&
&style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"&
&!-- Customize your theme here. --&
&item name="colorPrimary"&@color/colorPrimary&/item&
&item name="colorPrimaryDark"&@color/colorPrimaryDark&/item&
&item name="colorAccent"&@color/colorAccent&/item&
&style name="AppThemeTwo" parent="Theme.AppCompat.NoActionBar"&
&item name="android:windowBackground"&@android:color/transparent&/item&
&!-- Customize your theme here. --&
&item name="colorPrimary"&@color/colorPrimary&/item&
&item name="colorPrimaryDark"&@color/colorPrimaryDark&/item&
&item name="colorAccent"&@color/colorAccent&/item&
&/resources&
&?xml version="1.0" encoding="utf-8"?&
package="com.dapeng.laucherdemo"
xmlns:android="http://schemas.android.com/apk/res/android"&
&application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"&
android:name=".MainActivity"
android:theme="@style/AppThemeTwo"
&intent-filter&
&action android:name="android.intent.action.MAIN"/&
&category android:name="android.intent.category.LAUNCHER"/&
&/intent-filter&
&/activity&
&/application&
&/manifest&
如此一来问题就迎刃而解了.
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!

我要回帖

更多关于 实况足球2018白屏 的文章

 

随机推荐