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

时间:2018-07-29 12:26:41

标签: java android

我遇到的问题是,当我想在第一个活动“ ww1”和第二个活动“ ww2”之间切换时,我有一个白屏显示,我已经尝试了一种解决方案,说我应该在我的styles.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:

<?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" />

用于显示ww2.xml的代码:

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

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

1 个答案:

答案 0 :(得分:0)

使用它对我有用

 public Game GetGameData(int GameId)
            {
            var url = "https://store.steampowered.com/api/appdetails/?appids=" + GameId.ToString();
            //Game GameData = _download_serialized_json_data<Game>(url);
            HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(string.Format(url));

            WebReq.Method = "GET";

            HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();

            Console.WriteLine(WebResp.StatusCode);
            Console.WriteLine(WebResp.Server);

            string jsonString;
            using (Stream stream = WebResp.GetResponseStream())
            {
                StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8);
                jsonString = reader.ReadToEnd();
            }

            var dict = JsonConvert.DeserializeObject<Dictionary<string, Game>>(jsonString);

            Game gameData = dict[GameId.ToString()];

            return gameData;
        }

如果不工作,请使用它 在您的样式中添加

        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);

但是,更好的方法是在Activity.onCreate期间在主线程上执行较少的操作,并在用户等待时显示预览屏幕。为了顺利过渡,您可以在窗口中设置自定义背景,将其添加到主题中:

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