我正在尝试创建可放置在主屏幕上的图标/小部件(1 cell x 1 cell)。这个小部件的外观和动作完全像android中的其他标准快捷方式。它会有一个图标,在它下面有一个标签,它可以通过跟踪球进行选择(突出显示),当它被选中/点击时它会被突出显示。Android主屏幕小部件(图标,标签样式)
我该如何着手创建这个主屏幕小部件?
我是否必须自己使用code/xml创建窗口小部件,还是有一些标准的xml,样式,主题,代码可用于确保窗口小部件与其他主屏幕窗口小部件具有相同的样式/主题?
目前,我有以下
RES /绘制/ 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
<?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>
产生的小部件看起来有些什么接近,但它不可选,单击时不会突出显示,标签也不完全在正确的位置或正确的样式。
任何想法,如果有一个正确的方法来做到这一点,或者我应该继续努力,直到我离得更近?
你有没有找到一个解决方案,它将如何看起来像标准标签? – chrisonline 2011-06-15 08:58:35
下面的答案是正确的,你不会假设小部件看起来像快捷方式,因为不同的操作系统可能会显示不同的快捷方式!因此,如果您为HTC手机制作一个,它可能与MOTOBLUR手机上显示快捷方式的方式不一致。说,我反正做了我的一个看起来像HTC :) – dmulligan 2011-07-20 17:01:46