我正在嘗試創建可放置在主屏幕上的圖標/小部件(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