开发者

How to create android widget selectable?

The widget will look like standard application icon. Once user clicks on the widget, it should b开发者_JS百科e selected (highlighted with green background on HTC, with orange - on standard android).

How to achieve the same?

Upd. I've created it as selectable. Now I need to understand how to choose right background color/picture.


In the onReseive() deal with the listener.


Answering myself - it can be easily done by defining android:background="@drawable/shortcut_selector", then shortcut_selector.xml can contain something like

<?xml version="1.0" encoding="UTF-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/pressed_application_background" />
    <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/focused_application_background" />
    <item android:state_focused="true" android:state_window_focused="false" android:drawable="@android:color/transparent" />
</selector>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜