Android将标题添加到窗口小部件
答
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="72dp"
android:layout_height="wrap_content"
android:text="@string/label"
android:drawableTop="@drawable/icon"
/>
像这样的东西应该工作。使用drawableTop/Left/Right属性将允许您将图像放置在标签上方。完整的属性列表可以在here找到。
你可以尝试的另一件事是:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="72dp"
android:layout_height="wrap_content"
>
<TextView
android:text="@string/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_shape"
android:id="@+id/text"
/>
<ImageView
android:src="@drawable/icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:layout_above="@id/text"
/>
</RelativeLayout>
答
我不同意这个答案。 你不应该尝试这样做。
已经在这里讨论:
http://*.com/questions/2651631/android-home-screen-widget-icon-label-style/2652961#2652961
不错,做工精细。但是有什么办法可以获得相同的文字背景吗? (灰色,圆角) – Coxer 2010-10-14 14:23:15
我现在无法测试它,但是您可以使用可绘制圆角的形状,并执行'android:background =“@ drawable/background”'。不过,我不确定这是否仅包含文本,或者也包括上面提到的图像。 – kcoppock 2010-10-14 14:36:09
我已经测试过,它也包含图片 – Coxer 2010-10-14 14:56:34