2014-10-02 123 views
11

我在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)); 
     } 
    } 
  • 主題樣式初始屏幕圖像啓動畫面中的資源/值/ 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> 
    
  • 在資源飛濺抽拉/抽拉/ 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 --> 
    

    問題: 正如你可以看到,我使用的主題.Holo.Light作爲父主題,我在我的應用程序的其餘部分使用它。 Holo燈使用白色背景。 此白色背景不適用於SplashActivity背景。 SplashActivity背景始終爲黑色。 背景位圖(飛濺圖像)是可見的,但背景是黑色而不是白色。我使用透明度的PNG圖像。

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

    說明: 我使用Xamarin.Android,但造型對於Android平臺很常見。 Android版本4及以上。

    +0

    你設置在初始視圖的內容有何看法? – 2014-10-02 05:47:52

    +0

    不可以。只有樣式才能完成。沒有佈局。 – Ludwo 2014-10-02 06:00:37

    +0

    @Ludwo,你讓它成功了嗎? – 2014-11-11 15:56:25

    回答

    20

    在資源/繪製/ 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> 
    
    +0

    效果很好,實際上比自定義活動的解決方案更好,因爲主題早期顯示圖像 – 2016-01-30 20:43:37

    +0

    這是哪裏去的? – 2017-12-04 20:52:04

    +0

    @IanWarburton在resources/drawable/splash_centered.xml中。原始問題步驟4,圖層列表而不是位圖。 – minnow 2017-12-14 04:05:24

    8

    這就是我能夠在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> 
    

    NB:有一個在一輕微延遲飛濺png(標誌)來,但它仍然可以接受,比黑色背景更好。

    +0

    我的背景位圖(飛濺圖像)是可見的,但背景顏色是黑色而不是白色。這纔是重點。我使用透明度的PNG圖像。我更新了我的問題,以便更清楚。 – Ludwo 2014-11-29 11:52:58

    +0

    通過上述解決方法,您將獲得透明閃屏圖像的白色背景(在SplashActivity中)。 – Shibbs 2014-11-30 14:22:28

    +0

    我在網上找到的唯一解決方案。謝謝。 – phillipwei 2014-12-12 19:00:08