簡體   English   中英

飛濺屏幕活動背景顏色

[英]Splash screen activity background color

我在Android上的啟動畫面有問題。 在長時間應用程序啟動期間向用戶顯示啟動畫面,但活動背景始終為黑色。 我的意思是背景位圖(啟動圖像)是可見的,但背景是黑色而不是白色。 我正在使用具有透明度的PNG圖像。

我有的:

  1. PNG飛濺屏幕圖象有透明背景
  2. 啟動屏幕活動
    [Activity(MainLauncher = true, Theme = "@style/Theme.Splash", NoHistory = true)]
    public class SplashScreen : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Do your app initialization here
            // Other long running stuff

            // Run app when done
            StartActivity(typeof(MainForm));
        }
    }
  1. 資源/ values / styles.xml中的啟動畫面活動的主題樣式
    <resources>
      <style name="Theme.Splash" parent="@android:style/Theme.Holo.Light">
        <item name="android:windowBackground">@drawable/splash_centered</item>
        <item name="android:windowNoTitle">true</item>
      </style>
    </resources>
  1. Splash drawable in resources / drawable / splash_centered.xml
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/splash"
        android:gravity="center"
        android:background="@color/white"> <!-- this is ignored -->

問題:正如你所看到的,我正在使用Theme.Holo.Light作為父主題,我在我的應用程序的其余部分使用它。 Holo光使用白色背景。 此白色背景不適用於SplashActivity背景。 SplashActivity背景總是黑色的。 背景位圖(啟動圖像)可見,但背景為黑色而不是白色。 我正在使用具有透明度的PNG圖像。

問題:如何在SplashScreen活動中設置默認的Holo.Light主題背景顏色(白色)?

注意:我使用的是Xamarin.Android,但Android平台的樣式很常見。 Android版本4及更高版本。

在resources / drawable / splash_centered.xml中,使用圖層列表而不是位圖

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape android:shape="rectangle">
      <solid android:color="@android:color/white" />
    </shape>
  </item>
  <item>
    <bitmap android:gravity="center" android:src="@drawable/splash" />
  </item>
</layer-list>

這就是我在Xamarin中獲得白色背景飛濺(徽標居中)的方式。

[Activity (Theme= "@style/Theme.Splash", MainLauncher=true, NoHistory=true)]            
public class SplashActivity : Activity
{
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);
        SetContentView (Resource.Layout.splash);
        ThreadPool.QueueUserWorkItem (o => LoadActivity ());
        // Create your application here
    }
    private void LoadActivity() {
        Thread.Sleep (1000); // Simulate a long pause
        RunOnUiThread (() => StartActivity (typeof(MainActivity)));
    }
}

使用Theme.Splash:

<resources>
  <style name="Theme.Splash" parent="@android:style/Theme.Light">
    <item name="android:colorBackground">@android:color/white</item>
    <item name="android:windowNoTitle">true</item>
  </style>
</resources>

和splash.axml代碼(Theme.Light.NoTitleBar)為:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="25px"
    android:minHeight="25px"
    android:gravity="center">
    <ImageView
        android:src="@drawable/splash"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView1"
        android:layout_gravity="center" />
</LinearLayout>

注意:飛濺png(徽標)稍有延遲,但它仍然可以接受,比黑色背景更好。

將android:drawable =“@ color / colorWhite”設置為item。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/colorWhite" />

    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/splash" />
    </item>
</layer-list>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM