How can I make a home widget behave like a launcher icon?
Posted
by Tughi
on Stack Overflow
See other posts from Stack Overflow
or by Tughi
Published on 2010-01-26T18:48:13Z
Indexed on
2010/03/16
7:26 UTC
Read the original article
Hit count: 214
android
I have a widget that acts as a launcher on the home screen. How can I make it behave like a launcher icon?
I use this layout for portrait:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:background="@drawable/widget_background_selector"
android:focusable="true"
android:layout_width="74dip"
android:layout_height="79dip"
android:layout_marginLeft="3dip"
android:layout_marginTop="14dip">
<ImageView android:id="@android:id/background"
android:layout_width="72dip"
android:layout_height="72dip"
android:layout_marginLeft="1dip"
android:layout_marginTop="4dip" />
</RelativeLayout>
</RelativeLayout>
And this is the background selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/widget_background_pressed" />
<item android:state_window_focused="true" android:state_focused="true" android:drawable="@drawable/widget_background_focused" />
<item android:state_window_focused="false" android:state_focused="true" android:drawable="@android:color/transparent" />
</selector>
This way if I use the DPAD the widget is focusable but the click doesn't work. The touch still works but the widget is not displayed as focused.
Any idea what I do wrong?
© Stack Overflow or respective owner