What views can i use in an appWidget?

Can anyone tell me what views can I use in an appWidget?

Thank you!


Asked by: Max165 | Posted: 24-01-2022






Answer 1

according to the official android API:

A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:

  • FrameLayout
  • LinearLayout
  • RelativeLayout
  • GridLayout

And the following widget classes:

  • AnalogClock
  • Button
  • Chronometer
  • ImageButton
  • ImageView
  • ProgressBar
  • TextView
  • ViewFlipper
  • ListView
  • GridView
  • StackView
  • AdapterViewFlipper

Descendants of these classes are not supported.

RemoteViews also supports ViewStub, which is an invisible, zero-sized View you can use to lazily inflate layout resources at runtime.

Also starting with android 3.0 the next views are supported:

  • ListView - A view that shows items in a vertically scrolling list. For an example, see the Gmail app widget.
  • GridView - A view that shows items in two-dimensional scrolling grid. For an example, see the Bookmarks app widget.
  • StackView - A stacked card view (kind of like a rolodex), where the user can flick the front card up/down to see the previous/next card, respectively. Examples include the YouTube and Books app widgets.
  • AdapterViewFlipper - An adapter-backed simple ViewAnimator that animates between two or more views. Only one child is shown at a time.

Answered by: Edward525 | Posted: 25-02-2022



Answer 2

See the app widgets article on the Android Developers' site for a list of the layouts and views available for use in a widget.

Answered by: Aida654 | Posted: 25-02-2022



Answer 3

This list provided by Christopher is technically correct, but it is not quite complete. Although these layouts and views are available, many (most?) of the presentation methods cannot be invoked. For example, if you try to programmatically change the background color of one of the supported widgets (TextView), you will receive a runtime error:

WARN/AppWidgetHostView(606): android.widget.RemoteViews$ActionException: view: android.widget.TextView can't use method with RemoteViews: setBackgroundColor(int)

I've yet to see a definitive list of what is and is not supported. The android-dev list has seen a few threads (one, two) on the topic, but not much more. The work-arounds are not so great.

Answered by: Edward518 | Posted: 25-02-2022



Similar questions

android - Is it possible to receive SMS message on appWidget?

Is it possible to receive SMS message on appWidget? I saw android sample source(API Demos). In API Demos, ExampleAppWidgetProvider class extends AppWidgetProvider, not Activity. So, I guess it is impossible to regist SMS Receiver like this, rcvIncoming = new BroadcastReceiver() { @Override public v...


android - Looking for an elegant appwidget skin solution

I have an appwidget application and would like to enable users to create skins which can be applied at runtime. My preferred solution is to use apk files with nine patch png images that stretch to fit the ImageView's of widget, however its starting to look like I might have to use another packaging technique (e.g. zip files). What I've tried: Importing nine patch resources as Drawable with context.getResourcesForA...


android - Is it possible to receive SMS message on appWidget?

Is it possible to receive SMS message on appWidget? I saw android sample source(API Demos). In API Demos, ExampleAppWidgetProvider class extends AppWidgetProvider, not Activity. So, I guess it is impossible to regist SMS Receiver like this, rcvIncoming = new BroadcastReceiver() { @Override public v...


android - AppWidget only updates once

I have a problem with an appwidget. It doesn't have a configuration activity. When I set android:updatePeriodMillis="10000" ( know this shouldn't be done but it's just for testing) in the emulator the onUpdate(...) function is called every 10 seconds. But when i install my app on my real phone (motorola milestone) onUpdate(...) is only called when I add the widget to the home screen. ...


Android AppWidget layout troubles with ellipsize

I'm writing an app-widget that displays some numbers, each with label in front of it. The layout looks like this: .-----------------------------. | Label1 | AAAAAAAAAAA | | LongerLabelLabel2 | BBBBBBB | | LongLabel3 | CCCCCCCCCC | '-----------------------------' There is one outer (vertical) LinearLayout, and each row is a horizontal LinearLayout with two TextViews. ...


Is Toast allowed from an Android appWidget?

I would like to pop-up an error from the appwidget when one of its background tasks fails, but I don't think that is permissible -- or if it works, that it is safe.


android - Updating AppWidget

I'm launching an activity on a buttonclick from AppWidget. The user enters some data on the activity and when user closes the activity, I want to update the data user entered in a TextView on AppWidget. Any idea how to do that? I have successfully launched activity from AppWidget, only problem being updating the AppWidget.


Android appwidget not showing

Looked like my #$#%$%#$ the receiver was not i application element in manifest Hi I just created the helloworld appwidget to see how its works. i followed the dev example on adroid dev site. But for some reason the widget does not want to show in the widget list. AndroidManifest.xml <receiver android:name="VoiceRIAWidget" android:label="Voice RIA">...


android - appWidget layout reseting after device restart

I have a simple appWidget that displays an image. The image is selected in the configuration activity and the widget is updated via the remove view. This is done on a button push executing the code below: Intent intent = new Intent(context, KidDialog.class); intent.setData(selectedImage); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); widgetView.setOnClickPendingIntent(R....


Android AppWidget and App Single Signon

I have an App and an AppWidget associated with it. The AppWidget is updated by an Update Service. What I want to implement is that the AppWidget only starts getting updates only when the User has logged in, much like the Facebook/Twitter Application and AppWidget functionality on Android. If the User is not logged in, the Widget will show "Please log in" or something. Is there a standard way to implement this functionality...


android - applying a theme to an appwidget

I'm trying to define a theme for an appwidget, and have it applied at the application level. I have a theme like, <style name="theme.dark"> <item name="android"background">#000000</item> </style> in my manifest, I set android:theme="@style/theme.dark" at the application. however, when I run the appwidget, it does no...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top