Android Home Screen Widget (Icon, Label - Style)

Android Home Screen Widget (icon, label - style)

The "correct way to do this" is to make a shortcut, and not try to mimic it with an app widget. This has been pointed out repeatedly by the core Android team (notably Romain Guy) on the [android-developers] discussion list, such as:

Widgets should look like widgets, not
like shortcuts. The main reason is
that there is absolutely NO guarantee
about what a shortcut will look like.
Other devices (especially ones with
custom system UIs like MOTOBLUR or HTC
Sense) might have a different look and
feel. Or in the next update of Android
we might change the way shortcuts are
presented.

Android Widget Text Background

I would do something like:

<LinearLayout>
<ImageView/>
<TextView/>
</LinearLayout>

LinearLayout's background would be a <selector> aka StateListDrawable. The selector would specify a transparent background, that changes to orange when selected.

LinearLayout would also be the View you would set your PendingIntent on so that the user can click anywhere in the view and it will register as an onClick event.

As for your layout issues, you are just going to have to play with the layout to get the image and text to look like other icons on the home screen. I would think it wouldn't be that difficult to get a horizontally centered ImageView with a horizontally centered TextView below it, then just tweak the image dimensions and the text size till they look just like other icons on the home screen.

As for the problem you are seeing when you switch to Landscape view on your home screen, you will need to provide a landscape version of your layout XML file tweaked to display correctly in landscape mode. See my answer to this question for the method of doing that. When I make app widgets I usually get the portrait view looking perfect, then copy that layout file to the layout-land directory and start making tweaks until it looks like I want it to in landscape as well.

Top of the screen when the app is running showing a label with the app title

In your XML style file you should define these:

<style name="YourStyleName" parent="parentStyle">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>

Then restart, and it should work.



Related Topics



Leave a reply



Submit