Android Home Screen Widget (icon, label - style)

后端 未结 2 437
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 12:33

I\'m trying to create an icon/widget (1 cell x 1 cell) that can be placed on the home screen of android. The widget will look and act exactly like the other standard shortcu

相关标签:
2条回答
  • 2020-11-29 13:03

    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.

    0 讨论(0)
  • 2020-11-29 13:11

    To make your item consistent with the system look and feel is not hard by referencing the system attribute android:attr/selectableItemBackground. For example, if you want to make an ImageView in your widget look "selectable" with proper highlighting etc: just do

    <ImageView
        ...
        android:background="?android:attr/selectableItemBackground"
        ...
        />
    

    There are a lot in android_sdk_path/platforms/android-x. Happy digging!

    EDIT: I found out later that this simple attribute does not live in SDK < v11. So the best way I know now is to download the appwidget template pack and use it.

    0 讨论(0)
提交回复
热议问题