简体   繁体   English

在活动之间导航时,Android白屏显示

[英]Android, white screen is display when navigating between activities

The problem I have is that I have a white screen displayed when I want to switch between the 1st activity "ww1" and the 2nd activity "ww2", I have already tried a solution which says that I should create a theme in my styles.xml and add it to my second activity but the result was a black screen displayed while switching between the activity . 我的问题是,当我想在第一个活动“ ww1”和第二个活动“ ww2”之间切换时,我有一个白屏显示,我已经尝试了一种解决方案,说我应该以自己的样式创建一个主题。 xml并将其添加到我的第二个活动中,但结果是在活动之间切换时显示黑屏。

Here's the ww1.xml : 这是ww1.xml:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="@drawable/ww1"
   tools:context=".ww1">

<Button
    android:id="@+id/menu"
    android:layout_width="163dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/menu"
    android:visibility="visible" />

<Button
    android:id="@+id/next_btn"
    android:layout_width="55dp"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="210dp"
    android:background="@drawable/next"
    android:visibility="visible" />

ww2.XML : ww2.XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/ww2"
  tools:context=".ww2">

<Button
    android:id="@+id/menu"
    android:layout_width="163dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/menu"
    android:visibility="visible" />

<Button
    android:id="@+id/next_btn"
    android:layout_width="55dp"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignTop="@+id/previous_btn"
    android:background="@drawable/next"
    android:visibility="visible" />

<Button
    android:id="@+id/previous_btn"
    android:layout_width="57dp"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="211dp"
    android:background="@drawable/previous"
    android:visibility="visible" />

Code used to display the ww2.xml : 用于显示ww2.xml的代码:

            Intent mySuperIntent = new Intent(ww1.this, ww2.class);

            startActivity(mySuperIntent);
            overridePendingTransition(R.anim.slide_from_right,R.anim.slide_to_left);

Use it its worked for me 用它对我有用

        Intent mySuperIntent = new Intent(ww1.this, ww2.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(mySuperIntent);
        overridePendingTransition(R.anim.slide_from_right,R.anim.slide_to_left);

if dont work use it in Your style add 如果不工作,请在您的风格中使用它

          <style name="AppTheme" parent="Theme.AppCompat">
          <item name="android:windowDisablePreview">true</item>
          </style>

However a better approach is do less things on main thread during Activity.onCreate and let show the preview screen while user is waiting. 但是,更好的方法是在Activity.onCreate期间在主线程上执行较少的操作,并在用户等待时显示预览屏幕。 For a smooth transition, you can set a custom background to your windows adding this to your theme: 为了顺利过渡,您可以在窗口中设置自定义背景,将其添加到主题中:

     <style name="AppTheme" parent="Theme.AppCompat">
     <item name="android:windowBackground">@drawable/slash_screen</item>
     </style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM