2011-06-03 41 views
3

我試圖讓我的啓動畫面背景爲不透明/透明。我做的值colors.xml:Android啓動畫面,不透明背景不起作用

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<color name="translucent_black">#00000000</color> 
</resources> 

然後,我有我的splash.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:background="@color/translucent_black"> 
    <ImageView android:layout_width="wrap_content" android:id="@+id/imageView1" 
     android:src="@drawable/splash" android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_centerInParent="true"></ImageView> 

</RelativeLayout> 

我覺得我應該在清單的東西,但我不斷收到錯誤,把activitys英寸另外,如果你真的感覺活潑,我可以想出如何讓標題欄消失。再次感謝。

回答

10

簡單方法

指定要使用的半透明主題(在ma​​nifest.xml文件)的活動:

<activity ... 
      android:theme="@android:style/Theme.Translucent" 
      .../> 

高級方法

如果你想要更多的定製靈活性,您可以創建您自己的主題擴展半透明主題(manifest.xml):

<activity ... 
      android:theme="@android:style/Theme.MyTranslucentTheme" 
      .../> 

和styles.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

<style name="MyTranslucentTheme" parent="android:Theme.Translucent"> 
    <item name="android:windowBackground">@color/transparent_black</item> 
</style> 

<color name="transparent_black">#DA000000</color> 
</resources> 
+0

嘿謝謝!它要求提供一個屬性名稱,我應該把它稱爲什麼特殊的? – Nick 2011-06-03 17:30:15

+1

我不確定你做了什麼,以上應該就夠了。 – stealthcopter 2011-06-04 01:15:50

0

如果使用

< 活動 ... 機器人:主題= 「@安卓風格/ Theme.Translucent」

...... />

你必須在Activity中擴展Activity而不是AppCompatActivity .class繼承。