2015-05-12 40 views
5

Có cách nào để đặt màu thành biểu tượng có thể vẽ không? Vì vậy, màu của biểu tượng sẽ bị ghi đè bởi màu tùy chỉnh của tôi?Thay đổi màu của biểu tượng có thể vẽ xml

<item android:drawable="@drawable/icon1" 
    //set color to my icon here 
    android:state_pressed="true" /> 
<item android:drawable="@drawable/icon2" 
    //set color to my icon here 
    /> 
+0

Không, Bạn không thể đặt các màu sắc tùy chỉnh để các biểu tượng của bạn. Bạn chỉ có thể thay đổi màu nền của chế độ xem. cho điều này bạn có thể có hai biểu tượng của các màu sắc khác nhau và thiết lập các biểu tượng mong muốn theo trạng thái của nó. –

+0

Bạn đang tìm kiếm một bộ lọc màu [Điều này có thể giúp] (http://stackoverflow.com/questions/10114420/applying-colorfilter-to-imageview-with-shapeddrawable) – Skynet

+0

từ android 5.0 bạn có thể tô màu tài nguyên của bạn xem https: //developer.android.com/training/material/drawables.html#DrawableTint –

Trả lời

5

Trong android L (5.0) có một tính năng TINT cho phép thay đổi màu sắc của một drawable icon. Bạn có thể kiểm tra một ví dụ here.

Đối đầu APIs bạn phải sử dụng multiple drawables với selector chiến lược

5

Bạn có thể sử dụng đoạn mã này

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_checked="false"> 
     <bitmap android:src="@drawable/signup_checkbox_empty" android:tint="@color/turquoise" /> 
    </item> 
    <item android:state_checked="true"> 
     <bitmap android:src="@drawable/signup_checkbox_full" android:tint="@color/turquoise" /> 
    </item> 
    <item> 
     <bitmap android:src="@drawable/signup_checkbox_empty" android:tint="@color/turquoise" /> 
    </item> 
</selector> 
Các vấn đề liên quan