7

This is my question: My program have 2 widgets. One of them is 4x1 cells size. This widget has an icon(has the same width as widget itself) set in manifest file

android:icon="@drawable/widget_4bg"

My problem is that on android OS 4.x mobiles in the widget list, the icon is not spread on entire 4 cells but only in one.

enter image description here

How can I set correctly icon programmatically?

CocoNess
  • 4,213
  • 4
  • 26
  • 43
Alex
  • 239
  • 5
  • 12

1 Answers1

15

Try using this.

android:previewImage="@drawable/widget_4bg"

sample xml widget_info

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:initialLayout="@layout/your_widget_layout"
    android:minHeight="400dip"
    android:minResizeHeight="250dip"
    android:minResizeWidth="300dip"
    android:minWidth="450dip"
    android:previewImage="@drawable/widget_preview"
    android:resizeMode="horizontal|vertical"
    android:updatePeriodMillis="172800000" >

</appwidget-provider>

Update

 <receiver
            android:name="com..widget.WidgetProvider"
            >
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />

            </intent-filter>

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/widget_info" />
        </receiver>
Ali Imran
  • 8,927
  • 3
  • 39
  • 50
  • I have tried, it didn't working. I put it into manifest file, but it generates an error. – Alex Dec 08 '12 at 14:57
  • No don't put this in manifest, rather create a new xml like i provided and set this in your meta section of the widget receiver. like now i have shown above in updated code. – Ali Imran Dec 08 '12 at 15:02
  • unfortunately it generates error too: No resource identifier found for attribute 'previewImage' in package 'android' – Alex Dec 08 '12 at 15:38
  • I think I found an error. My Build Target version was set to Android 2.2. When I modified it to (3.0, minimum requirements for this propriety) It's starts working. But I have another question: If I modify build target to 11 (3.0) can it affect normally working of program on 2.2 (my minSdk version is 8)? – Alex Dec 08 '12 at 15:51
  • dagha da search da aala da.dagha da bnda dekha dekha da. – M.ArslanKhan Oct 08 '16 at 12:45