I am trying to create an icon / widget (cell 1 cell x 1) that can be placed on the Android main screen. The widget will look and act just like other standard shortcuts in android. It will have an icon and under this label, it will be selected using the trackball (backlighting is possible), it will be highlighted when selected / pressed.
How do I create this home screen widget?
Do I have to create the widget myself using the / xml code or is there some standard xml, style, theme, code that I can use to make sure the widget will have the same style / theme as other widgets on the main screen ?
I currently have
Res / draw / corners.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/Corners"> <stroke android:width="4dp" android:color="#CC222222" /> <padding android:left="4dp" android:top="1dp" android:right="4dp" android:bottom="1dp" /> <corners android:radius="4dp" /> </shape>
Res / layout / widget.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/Widget" android:layout_width="72dip" android:layout_height="72dip" android:orientation="vertical" android:focusable="true" android:gravity="center_horizontal" style="@android:style/Widget" > <ImageView android:id="@+id/WidgetIcon" android:src="@drawable/icon" android:layout_width="fill_parent" android:layout_height="50dip" android:paddingTop="3dip" android:gravity="center" /> <TextView android:id="@+id/WidgetLabel" android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="@string/app_name" android:textSize="15dip" android:background="@drawable/corners" /> </LinearLayout>
The resulting widget looks something like this, but cannot be selected, it does not stand out when pressed, and the label is not in the right place or in the right style.
Any ideas if there is a right way to do this, or should I just keep working on it until I get closer?
android android widget
dmulligan Apr 16 '10 at 8:39 2010-04-16 08:39
source share