2011-11-18 19 views
3

我創建了一個自定義控件作爲android庫。當我在android項目中使用這個控件時,如果我以編程方式聲明和使用它,但是我不能在XML上使用它,所以我遵循這個標準Declaring a custom android UI element using XML。在第一步中,我遇到這個錯誤在值 attrs.xml中聲明屬性時出錯

ERROR: In <declare-styleable> myView, unable to find attribute a:gender 
ERROR: In <declare-styleable> myView, unable to find attribute a:location 
.... 

而且這也對R.java文件

Syntax error, insert "}" to complete ClassBody 

這是我的價值觀\ attrs.xml圖書館

<?xml version="1.0" encoding="UTF-8"?> 
<resources> 
    <declare-styleable name="myView">      
     <attr name="a:location"/> 
     <attr name="a:gender"/>   
    </declare-styleable> 
</resources> 

上午我遺漏了什麼?。等待你的幫助。謝謝!

回答

4

回答我自己的問題。只要在attr名稱之前刪除「a:」,一切都會好起來的。

<?xml version="1.0" encoding="UTF-8"?> 
    <resources> 
     <declare-styleable name="myView">      
      <attr name="location"/> 
      <attr name="gender"/>   
     </declare-styleable> 
    </resources> 
+0

謝謝!它也適用於我! 但我想插入mynamespace:myattribute ..似乎不可能然後,但看起來像android是這樣做的,例如: 你有什麼想法嗎?我試過插入XMLNS,但它不起作用,不知道它是不是假設工作或我做錯了 – Zennichimaro