2016-06-30 20 views
1

我是Android開發新手。我正在嘗試使用XML文件爲我的第一個應用創建啓動畫面。然而,它給我下面的錯誤消息:<item>標籤需要'可繪製'屬性或子標籤定義可繪製

Rendering Problems Couldn't resolve resource @color/blue Failed to convert @color/blue into a drawable (Details) <item> tag requires a 'drawable' attribute or child tag defining a drawable 

我看了所有的地方,試圖找出如何獲得可繪製工作,卻找不到了。

這裏是我的代碼:

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

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

    <item> 
     <bitmap 
      android:gravity="center" 
      android:src="@mipmap/ic_launcher"/> 
    </item> 

</layer-list> 

回答

0

首先創建一個自定義繪製的文件,並添加標籤和應用你的顏色標記。那麼這給這個新創建的可繪製路徑android:drawable。

繪製/ bg_bule.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 
<solid android:color="@color/blue"/> 
</shape> 

然後把你的代碼:

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

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

<item 
    android:drawable="@drawable/bg_bule"/> 

<item> 
    <bitmap 
     android:gravity="center" 
     android:src="@mipmap/ic_launcher"/> 
</item> 

</layer-list>