[英]Is there a way to use declare-styleable to open the choose a resource dialog that lets you select a color or a drawable in Android Studio?
擁有自定義視圖TestView
並聲明以下自定義屬性:
<declare-styleable name="TestView">
<attr name="testAttr" format="reference"/>
</declare-styleable>
嘗試從 Android Studio 可視化編輯器中的屬性概覽打開資源選擇對話框時,該對話框將打開並且只允許選擇字符串資源。 如何修改上面的內容以顯示為視圖選擇背景資源時出現的相同對話框?
在此先感謝您的幫助! =)
編輯 - - -
我嘗試將代碼修改為:
<declare-styleable name="TestView">
<attr name="testAttr" format="reference|color" />
</declare-styleable>
因為這是我發現的android:background
,但只打開了選擇顏色資源的對話框。
如果要創建新顏色,則需要在colors.xml
“values”中編寫此代碼:(替換所需顏色的十六進制數)
<color name="white">#ffffff</color>
然后,一旦你創建了它,就在activity_main.xml
這樣調用它:(如果你想修改一個文本布局)
android:textColor="@color/white"
希望這能解決您的問題:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.