Android将标题添加到窗口小部件

问题描述:

我想添加一个标题,看起来像应用程序图标下面的默认文本到我的应用程序的窗口小部件。有什么常见的方法来实现这一点?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> 
+0

不错,做工精细。但是有什么办法可以获得相同的文字背景吗? (灰色,圆角) – Coxer 2010-10-14 14:23:15

+0

我现在无法测试它,但是您可以使用可绘制圆角的形状,并执行'android:background =“@ drawable/background”'。不过,我不确定这是否仅包含文本,或者也包括上面提到的图像。 – kcoppock 2010-10-14 14:36:09

+0

我已经测试过,它也包含图片 – Coxer 2010-10-14 14:56:34

我不同意这个答案。 你不应该尝试这样做。

已经在这里讨论:

http://*.com/questions/2651631/android-home-screen-widget-icon-label-style/2652961#2652961