简体   繁体   中英

Invert image color on click [Android]

I'm trying to do something like android default alarm clock app. When you click on the clock the icon turns black.

I have seen that there is only one clock image on android, ic_lock_idle_alarm. Then I think that android invert image programmatically.

I don't know how I could to do that.

I tried to set the invert image, created by photoshop with setBackgroundResource but the "black image" overlaps white image.

Otherwise I don't know which is the best approach.

Some advices? :-)

The Android default alarm clock app does not actually use ic_lock_idle_alarm but instead two PNG images from within the app, namely ic_clock_alarm_on (the normal icon) and ic_clock_alarm_selected (the black version). The black version is activated using android:state_pressed="true" android:state_window_focused="true" in a Drawable State List . This is also how I would recommend you to do it since it is for use cases like this Drawable State Lists exist, and since it is much easier than to do it programmatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM