Android主屏幕小部件(图标,标签 - 样式) [英] Android Home Screen Widget (icon, label - style)

查看:148
本文介绍了Android主屏幕小部件(图标,标签 - 样式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个图标/小部件(1电池×1电池),可放置了Android的主屏幕上。小部件的外观和行为完全像在Android的其他标准快捷方式。这将有一个图标和下一个标签,这将是选择与轨迹球(突出显示能够)被选择时,它也将被高亮显示/点击。

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 shortcuts in android. It will have an icon and under that a label, it will be selectable with the trackball (highlight able) it will be highlighted when it is selected/clicked.

我如何去创造这个主屏幕小工具?

How do I go about creating this home screen widget?

我必须使用code / XML创建窗口小部件自己还是有一些标准的XML格式,风格,主题,code,我可以使用,以确保部件将具有相同的样式/主题,其他主屏幕小部件?

Do I have to create the widget myself using code/xml or is there some standard xml, style, theme, code that I can use to ensure that the widget will have the same style/theme as the other home screen widgets?

目前,我有以下

RES /绘制/ corners.xml

res/drawable/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 /布局/ widget.xml

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 some what close, but its not selectable, it doesn't get highlighted when clicked and the label isn't exactly in the correct location or the correct style.

任何想法,如果这样做正确的方式,或者我应该保持上述工作距离,直到我更近?

Any ideas, if there is a correct way to do this, or should I just keep working away on the above until I am closer?

推荐答案

做这种正确的方法,就是要建立一个快捷方式,而不是试图与一个应用程序窗口小部件模仿它。这已经被反复指出的[Android的开发者]讨论列表,<一个在核心Android团队(尤其是罗曼盖伊) href="http://groups.google.com/group/android-developers/browse_thread/thread/37764678a00adddd/c8f9a7a822023698">such为:

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:

窗口小部件应该像小部件,而不是   喜欢的快捷键。主要的原因是   这是绝对没有的保证   什么快捷方式的样子。   其他设备(具有特别是那些   定制系统的UI像MOTOBLUR还是HTC   感)可能具有不同的外观和   感觉。还是在Android的下一次更新   我们可能会更改快捷方式的方法是   presented。

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主屏幕小部件(图标,标签 - 样式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆