RemoteViews | Android Developers
source link: https://developer.android.com/reference/android/widget/RemoteViews
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
- Android API Reference
- Overview
- Android Platform
- Packages
- API level
- Class Index
- Package Index
- android
- android.accessibilityservice
- android.accounts
- android.animation
- android.annotation
- android.app
- android.app.admin
- android.app.appsearch
- android.app.appsearch.exceptions
- android.app.assist
- android.app.backup
- android.app.blob
- android.app.job
- android.app.people
- android.app.role
- android.app.slice
- android.app.usage
- android.appwidget
- android.bluetooth
- android.bluetooth.le
- android.companion
- android.content
- android.content.pm
- android.content.res
- android.content.res.loader
- android.database
- android.database.sqlite
- android.drm
- android.gesture
- android.graphics
- android.graphics.drawable
- android.graphics.drawable.shapes
- android.graphics.fonts
- android.graphics.pdf
- android.graphics.text
- android.hardware
- android.hardware.biometrics
- android.hardware.camera2
- android.hardware.camera2.params
- android.hardware.display
- android.hardware.fingerprint
- android.hardware.input
- android.hardware.usb
- android.icu.lang
- android.icu.math
- android.icu.number
- android.icu.text
- android.icu.util
- android.inputmethodservice
- android.location
- android.location.provider
- android.media
- android.media.audiofx
- android.media.browse
- android.media.effect
- android.media.metrics
- android.media.midi
- android.media.projection
- android.media.session
- android.media.tv
- android.mtp
- android.net
- android.net.eap
- android.net.http
- android.net.ipsec.ike
- android.net.ipsec.ike.exceptions
- android.net.nsd
- android.net.rtp
- android.net.sip
- android.net.ssl
- android.net.vcn
- android.net.wifi
- android.net.wifi.aware
- android.net.wifi.hotspot2
- android.net.wifi.hotspot2.omadm
- android.net.wifi.hotspot2.pps
- android.net.wifi.p2p
- android.net.wifi.p2p.nsd
- android.net.wifi.rtt
- android.nfc
- android.nfc.cardemulation
- android.nfc.tech
- android.opengl
- android.os
- android.os.health
- android.os.storage
- android.os.strictmode
- android.preference
- android.print
- android.print.pdf
- android.printservice
- android.provider
- android.renderscript
- android.sax
- android.se.omapi
- android.security
- android.security.identity
- android.security.keystore
- android.service.autofill
- android.service.carrier
- android.service.chooser
- android.service.controls
- android.service.controls.actions
- android.service.controls.templates
- android.service.dreams
- android.service.media
- android.service.notification
- android.service.quickaccesswallet
- android.service.quicksettings
- android.service.restrictions
- android.service.textservice
- android.service.voice
- android.service.vr
- android.service.wallpaper
- android.speech
- android.speech.tts
- android.system
- android.telecom
- android.telephony
- android.telephony.cdma
- android.telephony.data
- android.telephony.emergency
- android.telephony.euicc
- android.telephony.gsm
- android.telephony.ims
- android.telephony.ims.feature
- android.telephony.mbms
- android.test
- android.test.mock
- android.test.suitebuilder
- android.test.suitebuilder.annotation
- android.text
- android.text.format
- android.text.method
- android.text.style
- android.text.util
- android.transition
- android.util
- android.util.proto
- android.view
- android.view.accessibility
- android.view.animation
- android.view.autofill
- android.view.contentcapture
- android.view.inputmethod
- android.view.inspector
- android.view.textclassifier
- android.view.textservice
- android.webkit
- android.widget
- android.widget.inline
- android.window
- com.android.net.module.util
- com.google.android.collect
- com.google.android.gles_jni
- com.google.android.util
- dalvik.annotation
- dalvik.bytecode
- dalvik.system
- java.awt.font
- java.beans
- java.io
- java.lang
- java.lang.annotation
- java.lang.invoke
- java.lang.ref
- java.lang.reflect
- java.math
- java.net
- java.nio
- java.nio.channels
- java.nio.channels.spi
- java.nio.charset
- java.nio.charset.spi
- java.nio.file
- java.nio.file.attribute
- java.nio.file.spi
- java.security
- java.security.acl
- java.security.cert
- java.security.interfaces
- java.security.spec
- java.sql
- java.text
- java.time
- java.time.chrono
- java.time.format
- java.time.temporal
- java.time.zone
- java.util
- java.util.concurrent
- java.util.concurrent.atomic
- java.util.concurrent.locks
- java.util.function
- java.util.jar
- java.util.logging
- java.util.prefs
- java.util.regex
- java.util.stream
- java.util.zip
- javax.crypto
- javax.crypto.interfaces
- javax.crypto.spec
- javax.microedition.khronos.egl
- javax.microedition.khronos.opengles
- javax.net
- javax.net.ssl
- javax.security.auth
- javax.security.auth.callback
- javax.security.auth.login
- javax.security.auth.x500
- javax.security.cert
- javax.sql
- javax.xml
- javax.xml.datatype
- javax.xml.namespace
- javax.xml.parsers
- javax.xml.transform
- javax.xml.transform.dom
- javax.xml.transform.sax
- javax.xml.transform.stream
- javax.xml.validation
- javax.xml.xpath
- junit.framework
- junit.runner
- org.apache.http.conn
- org.apache.http.conn.scheme
- org.apache.http.conn.ssl
- org.apache.http.params
- org.json
- org.w3c.dom
- org.w3c.dom.ls
- org.xml.sax
- org.xml.sax.ext
- org.xml.sax.helpers
- org.xmlpull.v1
- org.xmlpull.v1.sax2
Android 12 Developer Preview is here! Try it out, and give us your feedback!
RemoteViews
public
class
RemoteViews
extends Object
implements
Parcelable,
LayoutInflater.Filter
A class that describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy.
RemoteViews
is limited to support for the following layouts:
And the following widgets:
As of API 31, the following widgets and layouts may also be used:
Descendants of these classes are not supported.
Summary
Nested classes
class
RemoteViews.ActionException
Exception to send when something goes wrong executing an action
class
RemoteViews.RemoteResponse
Class representing a response to an action performed on any element of a RemoteViews.
@interface
RemoteViews.RemoteView
This annotation indicates that a subclass of View is allowed to be used
with the RemoteViews
mechanism.
class
RemoteViews.RemoteViewOutlineProvider
OutlineProvider for a view with a radius set by
RemoteViews.setViewOutlinePreferredRadius(int, float, int)
.
Constants
String
EXTRA_SHARED_ELEMENT_BOUNDS
The intent extra that contains the bounds for all shared elements.
Inherited constants
From interfaceandroid.os.Parcelable
Fields
public
static
final
Creator<RemoteViews>
CREATOR
Parcelable.Creator that instantiates RemoteViews objects
Public constructors
RemoteViews(String packageName, int layoutId)
Create a new RemoteViews object that will display the views contained in the specified layout file.
RemoteViews(RemoteViews landscape, RemoteViews portrait)
Create a new RemoteViews object that will inflate as the specified landspace or portrait RemoteViews, depending on the current configuration.
RemoteViews(Map<PointF, RemoteViews> remoteViews)
Create a new RemoteViews object that will inflate the layout with the closest size specification.
RemoteViews(RemoteViews src)
Creates a copy of another RemoteViews.
RemoteViews(Parcel parcel)
Reads a RemoteViews object from a parcel.
Public methods
void
addView(int viewId, RemoteViews nestedView)
Equivalent to calling ViewGroup#addView(View)
after inflating the
given RemoteViews
.
View
apply(Context context, ViewGroup parent)
Inflates the view hierarchy represented by this object and applies all of the actions.
RemoteViews
clone()
This method was deprecated
in API level 28.
use RemoteViews(android.widget.RemoteViews)
instead.
int
describeContents()
Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
int
getLayoutId()
Returns the layout id of the root layout associated with this RemoteViews.
String
getPackage()
boolean
onLoadClass(Class clazz)
This method is deprecated.
Used by system to enforce safe inflation of RemoteViews
. Apps should not
override this method. Changing of this method will NOT affect the process where RemoteViews
is rendered.
void
reapply(Context context, View v)
Applies all of the actions to the provided view.
void
removeAllViews(int viewId)
Equivalent to calling ViewGroup#removeAllViews()
.
void
setAccessibilityTraversalAfter(int viewId, int nextId)
Equivalent to calling View.setAccessibilityTraversalAfter(int)
.
void
setAccessibilityTraversalBefore(int viewId, int nextId)
Equivalent to calling View.setAccessibilityTraversalBefore(int)
.
void
setBitmap(int viewId, String methodName, Bitmap value)
Call a method taking one Bitmap on a view in the layout for this RemoteViews.
void
setBlendMode(int viewId, String methodName, BlendMode value)
Call a method taking one BlendMode on a view in the layout for this RemoteViews.
void
setBoolean(int viewId, String methodName, boolean value)
Call a method taking one boolean on a view in the layout for this RemoteViews.
void
setBundle(int viewId, String methodName, Bundle value)
Call a method taking one Bundle on a view in the layout for this RemoteViews.
void
setByte(int viewId, String methodName, byte value)
Call a method taking one byte on a view in the layout for this RemoteViews.
void
setChar(int viewId, String methodName, char value)
Call a method taking one char on a view in the layout for this RemoteViews.
void
setCharSequence(int viewId, String methodName, int stringResource)
Call a method taking one CharSequence on a view in the layout for this RemoteViews.
void
setCharSequence(int viewId, String methodName, CharSequence value)
Call a method taking one CharSequence on a view in the layout for this RemoteViews.
void
setChronometer(int viewId, long base, String format, boolean started)
Equivalent to calling Chronometer.setBase
,
Chronometer.setFormat
,
and Chronometer.start()
or
Chronometer.stop()
.
void
setChronometerCountDown(int viewId, boolean isCountDown)
Equivalent to calling Chronometer.setCountDown
on
the chronometer with the given viewId.
void
setColor(int viewId, String methodName, int colorResource)
Call a method taking one int, a color, on a view in the layout for this RemoteViews.
void
setColorStateList(int viewId, String methodName, int colorResource)
Call a method taking one ColorStateList on a view in the layout for this RemoteViews.
void
setCompoundButtonChecked(int viewId, boolean checked)
Equivalent to calling CompoundButton.setChecked(boolean)
.
void
setContentDescription(int viewId, CharSequence contentDescription)
Equivalent to calling View.setContentDescription(CharSequence).
void
setDisplayedChild(int viewId, int childIndex)
Equivalent to calling AdapterViewAnimator#setDisplayedChild(int)
void
setDouble(int viewId, String methodName, double value)
Call a method taking one double on a view in the layout for this RemoteViews.
void
setEmptyView(int viewId, int emptyViewId)
Equivalent to calling AdapterView#setEmptyView(View)
void
setFloat(int viewId, String methodName, float value)
Call a method taking one float on a view in the layout for this RemoteViews.
void
setFloatDimen(int viewId, String methodName, int dimenResource)
Call a method taking one float, a size in pixels, on a view in the layout for this RemoteViews.
void
setFloatDimen(int viewId, String methodName, float value, int unit)
Call a method taking one float, a size in pixels, on a view in the layout for this RemoteViews.
void
setIcon(int viewId, String methodName, Icon value)
Call a method taking one Icon on a view in the layout for this RemoteViews.
void
setImageViewBitmap(int viewId, Bitmap bitmap)
Equivalent to calling ImageView#setImageBitmap(Bitmap)
void
setImageViewIcon(int viewId, Icon icon)
Equivalent to calling ImageView#setImageIcon(Icon)
void
setImageViewResource(int viewId, int srcId)
Equivalent to calling ImageView#setImageResource(int)
void
setImageViewUri(int viewId, Uri uri)
Equivalent to calling ImageView#setImageURI(Uri)
void
setInt(int viewId, String methodName, int value)
Call a method taking one int on a view in the layout for this RemoteViews.
void
setIntDimen(int viewId, String methodName, float value, int unit)
Call a method taking one int, a size in pixels, on a view in the layout for this RemoteViews.
void
setIntDimen(int viewId, String methodName, int dimenResource)
Call a method taking one int, a size in pixels, on a view in the layout for this RemoteViews.
void
setIntent(int viewId, String methodName, Intent value)
Call a method taking one Intent on a view in the layout for this RemoteViews.
void
setLabelFor(int viewId, int labeledId)
Equivalent to calling View#setLabelFor(int)
.
void
setLightBackgroundLayoutId(int layoutId)
Provides an alternate layout ID, which can be used to inflate this view.
void
setLong(int viewId, String methodName, long value)
Call a method taking one long on a view in the layout for this RemoteViews.
void
setOnClickFillInIntent(int viewId, Intent fillInIntent)
When using collections (eg.
void
setOnClickPendingIntent(int viewId, PendingIntent pendingIntent)
Equivalent to calling
View.setOnClickListener(android.view.View.OnClickListener)
to launch the provided PendingIntent
.
void
setOnClickResponse(int viewId, RemoteViews.RemoteResponse response)
Equivalent of calling
View.setOnClickListener(android.view.View.OnClickListener)
to launch the provided RemoteResponse
.
void
setPendingIntentTemplate(int viewId, PendingIntent pendingIntentTemplate)
When using collections (eg.
void
setProgressBar(int viewId, int max, int progress, boolean indeterminate)
Equivalent to calling ProgressBar.setMax
,
ProgressBar.setProgress
, and
ProgressBar.setIndeterminate
If indeterminate is true, then the values for max and progress are ignored.
void
setRadioGroupChecked(int viewId, int checkedId)
Equivalent to calling RadioGroup.check(int)
.
void
setRelativeScrollPosition(int viewId, int offset)
Equivalent to calling ListView#smoothScrollByOffset(int)
.
void
setRemoteAdapter(int appWidgetId, int viewId, Intent intent)
This method was deprecated
in API level 15.
This method has been deprecated. See
setRemoteAdapter(int, Intent)
void
setRemoteAdapter(int viewId, Intent intent)
Equivalent to calling AbsListView.setRemoteViewsAdapter(Intent)
.
void
setScrollPosition(int viewId, int position)
Equivalent to calling ListView#smoothScrollToPosition(int)
.
void
setShort(int viewId, String methodName, short value)
Call a method taking one short on a view in the layout for this RemoteViews.
void
setString(int viewId, String methodName, String value)
Call a method taking one String on a view in the layout for this RemoteViews.
void
setTextColor(int viewId, int color)
Equivalent to calling TextView.setTextColor(int)
.
void
setTextViewCompoundDrawables(int viewId, int left, int top, int right, int bottom)
Equivalent to calling
TextView#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)
.
void
setTextViewCompoundDrawablesRelative(int viewId, int start, int top, int end, int bottom)
Equivalent to calling TextView.setCompoundDrawablesRelativeWithIntrinsicBounds(int, int, int, int)
.
void
setTextViewText(int viewId, CharSequence text)
Equivalent to calling TextView#setText(CharSequence)
void
setTextViewTextSize(int viewId, int units, float size)
Equivalent to calling TextView#setTextSize(int, float)
void
setUri(int viewId, String methodName, Uri value)
Call a method taking one Uri on a view in the layout for this RemoteViews.
void
setViewOutlinePreferredRadius(int viewId, float radius, int units)
Sets an OutlineProvider on the view whose corner radius is a dimension calculated using
TypedValue#applyDimension(int, float, DisplayMetrics)
.
void
setViewOutlinePreferredRadiusDimen(int viewId, int resId)
Sets an OutlineProvider on the view whose corner radius is a dimension resource with
resId
.
void
setViewPadding(int viewId, int left, int top, int right, int bottom)
Equivalent to calling View.setPadding(int, int, int, int)
.
void
setViewVisibility(int viewId, int visibility)
Equivalent to calling View#setVisibility(int)
void
showNext(int viewId)
Equivalent to calling AdapterViewAnimator#showNext()
void
showPrevious(int viewId)
Equivalent to calling AdapterViewAnimator#showPrevious()
void
writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel.
Constants
EXTRA_SHARED_ELEMENT_BOUNDS
public static final String EXTRA_SHARED_ELEMENT_BOUNDS
The intent extra that contains the bounds for all shared elements.
Constant Value: "android.widget.extra.SHARED_ELEMENT_BOUNDS"
Fields
CREATOR
public static final Creator<RemoteViews> CREATOR
Parcelable.Creator that instantiates RemoteViews objects
Public constructors
RemoteViews
public RemoteViews (String packageName, int layoutId)
Create a new RemoteViews object that will display the views contained in the specified layout file.
packageName
String
: Name of the package that contains the layout resource
layoutId
int
: The id of the layout resource
RemoteViews
public RemoteViews (RemoteViews landscape, RemoteViews portrait)
Create a new RemoteViews object that will inflate as the specified landspace or portrait RemoteViews, depending on the current configuration.
landscape
RemoteViews
: The RemoteViews to inflate in landscape configuration
portrait
RemoteViews
: The RemoteViews to inflate in portrait configuration
IllegalArgumentException
if either landscape or portrait are null or if they are
not from the same application
RemoteViews
public RemoteViews (Map<PointF, RemoteViews> remoteViews)
Create a new RemoteViews object that will inflate the layout with the closest size specification.
The default remote views in that case is always the smallest one provided.
remoteViews
Map
: Mapping of size to layout.
This value cannot be null
.
IllegalArgumentException
if the map is empty, there are more than
MAX_INIT_VIEW_COUNT layouts or the remote views are not all from the same application.
RemoteViews
public RemoteViews (RemoteViews src)
Creates a copy of another RemoteViews.
src
RemoteViews
Public methods
addView
public void addView (int viewId, RemoteViews nestedView)
Equivalent to calling ViewGroup#addView(View)
after inflating the
given RemoteViews
. This allows users to build "nested"
RemoteViews
. In cases where consumers of RemoteViews
may
recycle layouts, use removeAllViews(int)
to clear any existing
children.
viewId
int
: The id of the parent ViewGroup
to add child into.
nestedView
RemoteViews
: RemoteViews
that describes the child.
apply
public View apply (Context context, ViewGroup parent)
Inflates the view hierarchy represented by this object and applies all of the actions.
Caller beware: this may throw
context
Context
: Default context to use
parent
ViewGroup
: Parent that the resulting view hierarchy will be attached to. This method
does not attach the hierarchy. The caller should do so when appropriate.
View
The inflated view hierarchy
clone
public RemoteViews clone ()
This method was deprecated
in API level 28.
use RemoteViews(android.widget.RemoteViews)
instead.
Returns a deep copy of the RemoteViews object. The RemoteView may not be attached to another RemoteView -- it must be the root of a hierarchy.
RemoteViews
a clone of this instance.
IllegalStateException
if this is not the root of a RemoteView
hierarchy
describeContents
public int describeContents ()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation. For example, if the object will
include a file descriptor in the output of writeToParcel(android.os.Parcel, int)
,
the return value of this method must include the
CONTENTS_FILE_DESCRIPTOR
bit.
int
a bitmask indicating the set of special object types marshaled
by this Parcelable object instance.
Value is either 0
or CONTENTS_FILE_DESCRIPTOR
getLayoutId
public int getLayoutId ()
Returns the layout id of the root layout associated with this RemoteViews. In the case that the RemoteViews has both a landscape and portrait root, this will return the layout id associated with the portrait layout.
int
the layout id.
onLoadClass
public boolean onLoadClass (Class clazz)
This method is deprecated.
Used by system to enforce safe inflation of RemoteViews
. Apps should not
override this method. Changing of this method will NOT affect the process where RemoteViews
is rendered.
Used to restrict the views which can be inflated
clazz
Class
: The class object for the View that is about to be inflated
boolean
True if this class is allowed to be inflated, or false otherwise
reapply
public void reapply (Context context, View v)
Applies all of the actions to the provided view.
Caller beware: this may throw
context
Context
v
View
: The view to apply the actions to. This should be the result of
the apply(android.content.Context, android.view.ViewGroup)
call.
removeAllViews
public void removeAllViews (int viewId)
Equivalent to calling ViewGroup#removeAllViews()
.
setAccessibilityTraversalAfter
public void setAccessibilityTraversalAfter (int viewId, int nextId)
Equivalent to calling View.setAccessibilityTraversalAfter(int)
.
viewId
int
: The id of the view whose after view in accessibility traversal to set.
nextId
int
: The id of the next in the accessibility traversal.
setAccessibilityTraversalBefore
public void setAccessibilityTraversalBefore (int viewId, int nextId)
Equivalent to calling View.setAccessibilityTraversalBefore(int)
.
viewId
int
: The id of the view whose before view in accessibility traversal to set.
nextId
int
: The id of the next in the accessibility traversal.
setBitmap
public void setBitmap (int viewId, String methodName, Bitmap value)
Call a method taking one Bitmap on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
Bitmap
: The value to pass to the method.
setBlendMode
public void setBlendMode (int viewId, String methodName, BlendMode value)
Call a method taking one BlendMode on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
This value cannot be null
.
value
BlendMode
: The value to pass to the method.
This value may be null
.
setBoolean
public void setBoolean (int viewId, String methodName, boolean value)
Call a method taking one boolean on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
boolean
: The value to pass to the method.
setBundle
public void setBundle (int viewId, String methodName, Bundle value)
Call a method taking one Bundle on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
Bundle
: The value to pass to the method.
setByte
public void setByte (int viewId, String methodName, byte value)
Call a method taking one byte on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
byte
: The value to pass to the method.
setChar
public void setChar (int viewId, String methodName, char value)
Call a method taking one char on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
char
: The value to pass to the method.
setCharSequence
public void setCharSequence (int viewId, String methodName, int stringResource)
Call a method taking one CharSequence on a view in the layout for this RemoteViews.
The CharSequence will be resolved from the resources at the time of inflation.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
This value cannot be null
.
stringResource
int
: The resource to resolve and pass as argument to the method.
setCharSequence
public void setCharSequence (int viewId, String methodName, CharSequence value)
Call a method taking one CharSequence on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
CharSequence
: The value to pass to the method.
setChronometer
public void setChronometer (int viewId, long base, String format, boolean started)
Equivalent to calling Chronometer.setBase
,
Chronometer.setFormat
,
and Chronometer.start()
or
Chronometer.stop()
.
viewId
int
: The id of the Chronometer
to change
base
long
: The time at which the timer would have read 0:00. This
time should be based off of
SystemClock.elapsedRealtime()
.
format
String
: The Chronometer format string, or null to
simply display the timer value.
started
boolean
: True if you want the clock to be started, false if not.
See also:
setChronometerCountDown
public void setChronometerCountDown (int viewId, boolean isCountDown)
Equivalent to calling Chronometer.setCountDown
on
the chronometer with the given viewId.
viewId
int
: The id of the Chronometer
to change
isCountDown
boolean
: True if you want the chronometer to count down to base instead of
counting up.
setColor
public void setColor (int viewId, String methodName, int colorResource)
Call a method taking one int, a color, on a view in the layout for this RemoteViews.
The ColorStateList will be resolved from the resources at the time of inflation.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
This value cannot be null
.
colorResource
int
: The resource to resolve and pass as argument to the method.
setColorStateList
public void setColorStateList (int viewId, String methodName, int colorResource)
Call a method taking one ColorStateList on a view in the layout for this RemoteViews.
The ColorStateList will be resolved from the resources at the time of inflation.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
This value cannot be null
.
colorResource
int
: The resource to resolve and pass as argument to the method.
setCompoundButtonChecked
public void setCompoundButtonChecked (int viewId, boolean checked)
Equivalent to calling CompoundButton.setChecked(boolean)
.
viewId
int
: The id of the view whose property to set.
checked
boolean
: true to check the button, false to uncheck it.
setContentDescription
public void setContentDescription (int viewId, CharSequence contentDescription)
Equivalent to calling View.setContentDescription(CharSequence).
viewId
int
: The id of the view whose content description should change.
contentDescription
CharSequence
: The new content description for the view.
setDisplayedChild
public void setDisplayedChild (int viewId, int childIndex)
Equivalent to calling AdapterViewAnimator#setDisplayedChild(int)
viewId
int
: The id of the view on which to call
AdapterViewAnimator#setDisplayedChild(int)
childIndex
int
setDouble
public void setDouble (int viewId, String methodName, double value)
Call a method taking one double on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
double
: The value to pass to the method.
setEmptyView
public void setEmptyView (int viewId, int emptyViewId)
Equivalent to calling AdapterView#setEmptyView(View)
viewId
int
: The id of the view on which to set the empty view
emptyViewId
int
: The view id of the empty view
setFloat
public void setFloat (int viewId, String methodName, float value)
Call a method taking one float on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
float
: The value to pass to the method.
setFloatDimen
public void setFloatDimen (int viewId, String methodName, int dimenResource)
Call a method taking one float, a size in pixels, on a view in the layout for this RemoteViews.
The dimension will be resolved from the resources at the time of inflation.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
This value cannot be null
.
dimenResource
int
: The resource to resolve and pass as argument to the method.
setFloatDimen
public void setFloatDimen (int viewId, String methodName, float value, int unit)
Call a method taking one float, a size in pixels, on a view in the layout for this RemoteViews.
The dimension will be resolved from the specified dimension at the time of inflation.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
This value cannot be null
.
value
float
: The value of the dimension.
unit
int
: The unit in which the value is specified.
Value is TypedValue.COMPLEX_UNIT_PX
, TypedValue.COMPLEX_UNIT_DIP
, TypedValue.COMPLEX_UNIT_SP
, TypedValue.COMPLEX_UNIT_PT
, TypedValue.COMPLEX_UNIT_IN
, or TypedValue.COMPLEX_UNIT_MM
setIcon
public void setIcon (int viewId, String methodName, Icon value)
Call a method taking one Icon on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
Icon
: The Icon
to pass the method.
setImageViewBitmap
public void setImageViewBitmap (int viewId, Bitmap bitmap)
Equivalent to calling ImageView#setImageBitmap(Bitmap)
viewId
int
: The id of the view whose bitmap should change
bitmap
Bitmap
: The new Bitmap for the drawable
setImageViewIcon
public void setImageViewIcon (int viewId, Icon icon)
Equivalent to calling ImageView#setImageIcon(Icon)
viewId
int
: The id of the view whose bitmap should change
icon
Icon
: The new Icon for the ImageView
setImageViewResource
public void setImageViewResource (int viewId, int srcId)
Equivalent to calling ImageView#setImageResource(int)
viewId
int
: The id of the view whose drawable should change
srcId
int
: The new resource id for the drawable
setImageViewUri
public void setImageViewUri (int viewId, Uri uri)
Equivalent to calling ImageView#setImageURI(Uri)
viewId
int
: The id of the view whose drawable should change
uri
Uri
: The Uri for the image
setInt
public void setInt (int viewId, String methodName, int value)
Call a method taking one int on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
int
: The value to pass to the method.
setIntDimen
public void setIntDimen (int viewId, String methodName, float value, int unit)
Call a method taking one int, a size in pixels, on a view in the layout for this RemoteViews.
The dimension will be resolved from the specified dimension at the time of inflation.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
This value cannot be null
.
value
float
: The value of the dimension.
unit
int
: The unit in which the value is specified.
Value is TypedValue.COMPLEX_UNIT_PX
, TypedValue.COMPLEX_UNIT_DIP
, TypedValue.COMPLEX_UNIT_SP
, TypedValue.COMPLEX_UNIT_PT
, TypedValue.COMPLEX_UNIT_IN
, or TypedValue.COMPLEX_UNIT_MM
setIntDimen
public void setIntDimen (int viewId, String methodName, int dimenResource)
Call a method taking one int, a size in pixels, on a view in the layout for this RemoteViews.
The dimension will be resolved from the resources at the time of inflation.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
This value cannot be null
.
dimenResource
int
: The resource to resolve and pass as argument to the method.
setIntent
public void setIntent (int viewId, String methodName, Intent value)
Call a method taking one Intent on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
Intent
: The Intent
to pass the method.
setLabelFor
public void setLabelFor (int viewId, int labeledId)
Equivalent to calling View#setLabelFor(int)
.
viewId
int
: The id of the view whose property to set.
labeledId
int
: The id of a view for which this view serves as a label.
setLightBackgroundLayoutId
public void setLightBackgroundLayoutId (int layoutId)
Provides an alternate layout ID, which can be used to inflate this view. This layout will be used by the host when the widgets displayed on a light-background where foreground elements and text can safely draw using a dark color without any additional background protection.
layoutId
int
setLong
public void setLong (int viewId, String methodName, long value)
Call a method taking one long on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
long
: The value to pass to the method.
setOnClickFillInIntent
public void setOnClickFillInIntent (int viewId, Intent fillInIntent)
When using collections (eg. ListView
, StackView
etc.) in widgets, it is very
costly to set PendingIntents on the individual items, and is hence not recommended. Instead
a single PendingIntent template can be set on the collection, see setPendingIntentTemplate(int, android.app.PendingIntent)
, and the individual on-click
action of a given item can be distinguished by setting a fillInIntent on that item. The
fillInIntent is then combined with the PendingIntent template in order to determine the final
intent which will be executed when the item is clicked. This works as follows: any fields
which are left blank in the PendingIntent template, but are provided by the fillInIntent
will be overwritten, and the resulting PendingIntent will be used. The rest
of the PendingIntent template will then be filled in with the associated fields that are
set in fillInIntent. See Intent#fillIn(Intent, int)
for more details.
viewId
int
: The id of the view on which to set the fillInIntent
fillInIntent
Intent
: The intent which will be combined with the parent's PendingIntent
in order to determine the on-click behavior of the view specified by viewId
setOnClickPendingIntent
public void setOnClickPendingIntent (int viewId, PendingIntent pendingIntent)
Equivalent to calling
View.setOnClickListener(android.view.View.OnClickListener)
to launch the provided PendingIntent
. The source bounds
(Intent#getSourceBounds()
) of the intent will be set to the bounds of the clicked
view in screen space.
Note that any activity options associated with the mPendingIntent may get overridden
before starting the intent.
When setting the on-click action of items within collections (eg. ListView
,
StackView
etc.), this method will not work. Instead, use setPendingIntentTemplate(int, android.app.PendingIntent)
in conjunction with
RemoteViews#setOnClickFillInIntent(int, Intent)
.
viewId
int
: The id of the view that will trigger the PendingIntent
when clicked
pendingIntent
PendingIntent
: The PendingIntent
to send when user clicks
setOnClickResponse
public void setOnClickResponse (int viewId, RemoteViews.RemoteResponse response)
Equivalent of calling
View.setOnClickListener(android.view.View.OnClickListener)
to launch the provided RemoteResponse
.
viewId
int
: The id of the view that will trigger the RemoteResponse
when clicked
response
RemoteViews.RemoteResponse
: The RemoteResponse
to send when user clicks
This value cannot be null
.
setPendingIntentTemplate
public void setPendingIntentTemplate (int viewId, PendingIntent pendingIntentTemplate)
When using collections (eg. ListView
, StackView
etc.) in widgets, it is very
costly to set PendingIntents on the individual items, and is hence not recommended. Instead
this method should be used to set a single PendingIntent template on the collection, and
individual items can differentiate their on-click behavior using
RemoteViews#setOnClickFillInIntent(int, Intent)
.
viewId
int
: The id of the collection who's children will use this PendingIntent template
when clicked
pendingIntentTemplate
PendingIntent
: The PendingIntent
to be combined with extras specified
by a child of viewId and executed when that child is clicked
setProgressBar
public void setProgressBar (int viewId, int max, int progress, boolean indeterminate)
Equivalent to calling ProgressBar.setMax
,
ProgressBar.setProgress
, and
ProgressBar.setIndeterminate
If indeterminate is true, then the values for max and progress are ignored.
viewId
int
: The id of the ProgressBar
to change
max
int
: The 100% value for the progress bar
progress
int
: The current value of the progress bar.
indeterminate
boolean
: True if the progress bar is indeterminate,
false if not.
setRadioGroupChecked
public void setRadioGroupChecked (int viewId, int checkedId)
Equivalent to calling RadioGroup.check(int)
.
viewId
int
: The id of the view whose property to set.
checkedId
int
: The unique id of the radio button to select in the group.
setRelativeScrollPosition
public void setRelativeScrollPosition (int viewId, int offset)
Equivalent to calling ListView#smoothScrollByOffset(int)
.
viewId
int
: The id of the view to change
offset
int
: Scroll by this adapter position offset
setRemoteAdapter
public void setRemoteAdapter (int appWidgetId, int viewId, Intent intent)
This method was deprecated
in API level 15.
This method has been deprecated. See
setRemoteAdapter(int, Intent)
Equivalent to calling AbsListView.setRemoteViewsAdapter(Intent)
.
appWidgetId
int
: The id of the app widget which contains the specified view. (This
parameter is ignored in this deprecated method)
viewId
int
: The id of the AdapterView
intent
Intent
: The intent of the service which will be
providing data to the RemoteViewsAdapter
setRemoteAdapter
public void setRemoteAdapter (int viewId, Intent intent)
Equivalent to calling AbsListView.setRemoteViewsAdapter(Intent)
.
Can only be used for App Widgets.
viewId
int
: The id of the AdapterView
intent
Intent
: The intent of the service which will be
providing data to the RemoteViewsAdapter
setScrollPosition
public void setScrollPosition (int viewId, int position)
Equivalent to calling ListView#smoothScrollToPosition(int)
.
viewId
int
: The id of the view to change
position
int
: Scroll to this adapter position
setShort
public void setShort (int viewId, String methodName, short value)
Call a method taking one short on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
short
: The value to pass to the method.
setString
public void setString (int viewId, String methodName, String value)
Call a method taking one String on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
String
: The value to pass to the method.
setTextColor
public void setTextColor (int viewId, int color)
Equivalent to calling TextView.setTextColor(int)
.
viewId
int
: The id of the view whose text color should change
color
int
: Sets the text color for all the states (normal, selected,
focused) to be this color.
setTextViewCompoundDrawables
public void setTextViewCompoundDrawables (int viewId, int left, int top, int right, int bottom)
Equivalent to calling
TextView#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)
.
viewId
int
: The id of the view whose text should change
left
int
: The id of a drawable to place to the left of the text, or 0
top
int
: The id of a drawable to place above the text, or 0
right
int
: The id of a drawable to place to the right of the text, or 0
bottom
int
: The id of a drawable to place below the text, or 0
setTextViewCompoundDrawablesRelative
public void setTextViewCompoundDrawablesRelative (int viewId, int start, int top, int end, int bottom)
Equivalent to calling TextView.setCompoundDrawablesRelativeWithIntrinsicBounds(int, int, int, int)
.
viewId
int
: The id of the view whose text should change
start
int
: The id of a drawable to place before the text (relative to the
layout direction), or 0
top
int
: The id of a drawable to place above the text, or 0
end
int
: The id of a drawable to place after the text, or 0
bottom
int
: The id of a drawable to place below the text, or 0
setTextViewText
public void setTextViewText (int viewId, CharSequence text)
Equivalent to calling TextView#setText(CharSequence)
viewId
int
: The id of the view whose text should change
text
CharSequence
: The new text for the view
setTextViewTextSize
public void setTextViewTextSize (int viewId, int units, float size)
Equivalent to calling TextView#setTextSize(int, float)
viewId
int
: The id of the view whose text size should change
units
int
: The units of size (e.g. COMPLEX_UNIT_SP)
size
float
: The size of the text
setUri
public void setUri (int viewId, String methodName, Uri value)
Call a method taking one Uri on a view in the layout for this RemoteViews.
viewId
int
: The id of the view on which to call the method.
methodName
String
: The name of the method to call.
value
Uri
: The value to pass to the method.
setViewOutlinePreferredRadius
public void setViewOutlinePreferredRadius (int viewId, float radius, int units)
Sets an OutlineProvider on the view whose corner radius is a dimension calculated using
TypedValue#applyDimension(int, float, DisplayMetrics)
. This outline may change shape
during system transitions.
NOTE: It is recommended to use TypedValue#COMPLEX_UNIT_PX
only for 0.
Setting margins in pixels will behave poorly when the RemoteViews object is used on a
display with a different density.
setViewOutlinePreferredRadiusDimen
public void setViewOutlinePreferredRadiusDimen (int viewId, int resId)
Sets an OutlineProvider on the view whose corner radius is a dimension resource with
resId
. This outline may change shape during system transitions.
viewId
int
resId
int
setViewPadding
public void setViewPadding (int viewId, int left, int top, int right, int bottom)
Equivalent to calling View.setPadding(int, int, int, int)
.
viewId
int
: The id of the view to change
left
int
: the left padding in pixels
This units of this value are pixels.
top
int
: the top padding in pixels
This units of this value are pixels.
right
int
: the right padding in pixels
This units of this value are pixels.
bottom
int
: the bottom padding in pixels
This units of this value are pixels.
setViewVisibility
public void setViewVisibility (int viewId, int visibility)
Equivalent to calling View#setVisibility(int)
viewId
int
: The id of the view whose visibility should change
visibility
int
: The new visibility for the view
Value is View.VISIBLE
, View.INVISIBLE
, or View.GONE
showPrevious
public void showPrevious (int viewId)
Equivalent to calling AdapterViewAnimator#showPrevious()
writeToParcel
public void writeToParcel (Parcel dest, int flags)
Flatten this object in to a Parcel.
dest
Parcel
: The Parcel in which the object should be written.
flags
int
: Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.
Value is either 0
or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE
, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-03-17 UTC.
-
Follow @AndroidDev on Twitter
-
Check out Android Developers on YouTube
Recommend
-
144
Distribution dashboard Thank you for your patience! We're working to improve the insights we provide to you about the Android ecosystem and the ways...
-
105
Professionals | Community Groups Programs | Google Developers
-
142
These are the Best Pixel Phones to buy in 2022 Google Pixel phones are often ranked as the “god tier” of the
-
96
Making Pixel better for Drivers 09 November 2017 ...
-
136
Final preview of Android 8.1 now available 27 November 2...
-
125
-
121
Welcoming Android 8.1 Oreo and Android Oreo (Go edition)
-
1
android.widget.RemoteViews Android Developers | Android.com API Diff Specification To Level: s-dp2 From Level:...
-
29
桌面小组件AppWidget - RemoteViews for widget update exceeds maximum bitmap memory usage ...
-
1
聊聊RemoteViews在Android应用程序中的使用 作者:Reathin 2023-12-07 08:22:58 RemoteViews 的内部机制涉及到跨进程通信(IPC),它通过序列化和反序列化来传递布局和操作指令。当我们在一个应用程序中使用 Remot...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK