初始屏幕活动背景颜色

初始屏幕活动背景颜色

问题描述:

我在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. 主题样式初始屏幕图像启动画面中的资源/值/ styles.xml活动
  2. <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_centered.xml
    2. <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

在资源/绘制/ 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

这就是我能够在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