1

i want to add a caption which looks like the default text below an app icon to the widget of my app. Is there any common way to achieve this?

Coxer
  • 549
  • 1
  • 8
  • 8

2 Answers2

1
<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"
/>

Something like this should work. Using the drawableTop/Left/Right attributes will allow you to place an image above the label. A full list of attributes can be found here.

Another thing you could try is:

<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>
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
  • Nice, works fine. But is there any way to get the same background for the text? (grey, rounded corners) – Coxer Oct 14 '10 at 14:23
  • I can't test it right now, but you could probably use a shape drawable with rounded corners, and do `android:background="@drawable/background"`. I'm not sure whether that would cover only the text, or also the image drawable above as well, though. – Kevin Coppock Oct 14 '10 at 14:36
  • I've added a new suggestion. Again, I can't test right now unfortunately. :( I'm not sure I have the right wording for scaleType (might be fit_center?) – Kevin Coppock Oct 14 '10 at 15:34
0

I disagree with this answer. You should not try to do this.

It has been discussed here :

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

Anthony Chatellier
  • 594
  • 1
  • 4
  • 15