Thông báo lỗi tôi nhận được cho việc này là:
org.xmlpull.v1.XmlPullParserException: Binary XML file line #18: <item> tag requires a 'drawable' attribute or child tag defining a drawable
Làm một chút đào, các thông số kỹ thuật nói thuộc tính background
nên hỗ trợ hoặc là một màu, hoặc tham chiếu đến một tài nguyên drawable:
.. Nhìn vào tài nguyên bạn đang tham chiếu, nó là a StateListDrawable
.
platforms/android-17/data/res/color/primary_text_dark.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@android:color/bright_foreground_dark_disabled"/>
<item android:state_window_focused="false" android:color="@android:color/bright_foreground_dark"/>
<item android:state_pressed="true" android:color="@android:color/bright_foreground_dark_inverse"/>
<item android:state_selected="true" android:color="@android:color/bright_foreground_dark_inverse"/>
<item android:state_activated="true" android:color="@android:color/bright_foreground_dark_inverse"/>
<item android:color="@android:color/bright_foreground_dark"/> <!-- not selected -->
</selector>
Tuy nhiên, các tài liệu cho StateListDrawable cũng dứt khoát nói thuộc tính drawable
phải được xác định cho item
yếu tố:
https://developer.android.com/guide/topics/resources/drawable-resource.html
<item>
Defines a drawable to use during certain states, as described by its attributes. Must be a child of a <selector> element.
attributes:
android:drawable
Drawable resource. Required. Reference to a drawable resource.
... mà không phải là trường hợp đối với trường hợp cho primary_text_dark.xml
. Vì vậy, nó không làm việc vì drawable bạn đang tham khảo dường như không phù hợp với spec.
Tôi nghĩ rằng giải pháp thay thế là để tham chiếu màu được sử dụng trong primary_text_dark
cho trạng thái mặc định: bright_foreground_dark
.Thấy rằng không công khai, bạn cần truy cập trực tiếp vào tài liệu tham chiếu, nghĩa là:
android:background="@android:color/background_light"
truy vấn tương tự đã được nêu ra [link] (http://stackoverflow.com/questions/5850597/consistent-ui- color-in-all-android-devices) Ở đây Hy vọng nó hữu ích cho bạn – Ashish
@ Aishish: không có gì, các câu hỏi khác muốn biết cách thiết lập màu nói chung, tôi muốn biết cách sử dụng textColorPrimary như màu backgronud . – johannes
Bạn có thể lấy màu theo cách thủ công bằng cách làm như sau: 'textView.getCurrentTextColor();' và lấy màu này từ một TextView sử dụng nó. Nếu bạn muốn kiểm soát việc sử dụng màu này: '- # FFFFFF
' cho màu đen chẳng hạn OR ' '. Cho tôi biết nếu đó là những gì bạn muốn làm. –
g00dy