2017-07-31 71 views
12

我使用Android 2.3.3工作室穩定,並試圖爲AndroidØ元自適應圖標必須聲明

我創建的文件夾mipmap-anydpi-v26創建自適應圖標,然後用下面的內容

<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> 
    <background android:drawable="@color/colorAccent"/> 
    <foreground android:drawable="@drawable/ic_launcher_adaptive"/> 
</adaptive-icon> 

文件ic_launcher.xml但它說「元素自適應圖標必須聲明」。 目標SDK和構建工具都設置爲26.

它構建成功,但我沒有任何設備來測試它,所以我的問題是 - 它是否工作?

P.S:前景是有效VectorDrawable

+1

「我沒有任何設備進行測試」 - 測試它的API等級26模擬器。 – CommonsWare

+0

然後購買能夠運行O Developer Preview並對其進行測試的設備。 – CommonsWare

+1

我可以確認這會在使用Android Studio版本2.3.3構建時起作用,儘管我只使用可繪製的位圖進行測試,而不使用矢量繪製。 – M66B

回答

11

我建議你創建Android Studio中的虛擬設備管理器的Android O虛擬設備用於測試自適應的圖標。我也在Android Studio 2.3.3中出現相同的錯誤。看起來像Android Studio 2.3.3不支持自適應圖標標籤。我們需要爲此獲取Android Studio 3.0。

自適應圖標在Android開發者網站即使文檔顯示過Android Studio 3.0截圖

https://developer.android.com/preview/features/adaptive-icons.html

編輯: - 我已經檢查並發現了自適應圖標是工作在應用罰款從Android Studio中2.3建設。 3不管「元素自適應圖標必須聲明」錯誤。

+0

我收到一個錯誤「錯誤:(2)解析XML時出錯:未綁定前綴」並且構建失敗。 – Gaket

+0

您是否在xml文件的頂部添加了XML NameSpace <?xml version =「1.0」encoding =「utf-8」?>? –

+0

是的,謝謝。最後我發現我的問題,它在下面的答案。 – Gaket

1

ic_launcher.xml應該是這樣的

<?xml version="1.0" encoding="utf-8"?> 
    <adaptive-icon 
     xmlns:android="http://schemas.android.com/apk/res/android"> 
     <background android:drawable="@color/white"/> 
     <foreground android:drawable="@mipmap/ic_launcher_foreground"/> 
    </adaptive-icon>