Android Notification 基础 (三)

本文介绍了Android中RemoteViews类的使用方法及常见API。RemoteViews用于在其他进程中显示View对象,尤其适用于Widget开发。文章通过示例展示了如何实例化并更新RemoteViews。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

remoteviews

2011-04-22 14:58:14|分类: Android 杂记 |标签:intremoteviewsviewidvoidlayout |字号订阅

RemoteViews类描述了一个View对象能够显示在其他进程中,可以融合从一个 layout资源文件实现布局。虽然该类在android.widget.RemoteViews而不是appWidget下面但在Android Widgets开发中会经常用到它,主要是可以跨进程调用(appWidget由一个服务宿主来统一运行的)。

如何实例化一个RemoteViews

构造方法
<nobr></nobr> <nobr><span>RemoteViews</span>(String packageName, int layoutId)</nobr>
创建一个新的RemoteViews对象将显示 views包含指定一个layout资源.
<nobr></nobr> <nobr><span>RemoteViews</span>(Parcel parcel)</nobr>
读取RemoteViews对象从一个parcel中.

首先给大家一段例子简单说明下构造和如何使用

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider);
views.setTextViewText(R.id.appwidget_text, "Android开发网欢迎您");

appWidgetManager.updateAppWidget(appWidgetId, views);

详细的 该类的公共方法列表,下面的viewId为layout文件中的id定义,常用的方法已经翻译成中文描述。

Public Methods
<nobr>View</nobr> <nobr><span>apply</span>(Context context, ViewGroup parent)</nobr>
Inflates the view hierarchy represented by this object and applies all of the actions.
<nobr>int</nobr> <nobr><span>describeContents</span>()</nobr>
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
<nobr>int</nobr><nobr><span>getLayoutId</span>()</nobr>
<nobr>String</nobr><nobr><span>getPackage</span>()</nobr>
<nobr>boolean</nobr> <nobr><span>onLoadClass</span>(Class clazz)</nobr>
Hook to allow clients of the LayoutInflater to restrict the set of Views that are allowed to be inflated.
<nobr>void</nobr> <nobr><span>reapply</span>(Context context, View v)</nobr>
Applies all of the actions to the provided view.
<nobr>void</nobr> <nobr><span>setBitmap</span>(int viewId, String methodName, Bitmap value)</nobr>
Call a method taking one Bitmap on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setBoolean</span>(int viewId, String methodName, boolean value)</nobr>
Call a method taking one boolean on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setByte</span>(int viewId, String methodName, byte value)</nobr>
Call a method taking one byte on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setChar</span>(int viewId, String methodName, char value)</nobr>
Call a method taking one char on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setCharSequence</span>(int viewId, String methodName, CharSequence value)</nobr>
Call a method taking one CharSequence on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setChronometer</span>(int viewId, long base, String format, boolean started)</nobr>
Equivalent to calling Chronometer.setBase, Chronometer.setFormat, and Chronometer.start() or Chronometer.stop().
<nobr>void</nobr> <nobr><span>setDouble</span>(int viewId, String methodName, double value)</nobr>
Call a method taking one double on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setFloat</span>(int viewId, String methodName, float value)</nobr>
Call a method taking one float on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setImageViewBitmap</span>(int viewId, Bitmap bitmap)</nobr>
等同于调用ImageView.setImageBitmap方法,从 Bitmap对象中设置一个图片
<nobr>void</nobr> <nobr><span>setImageViewResource</span>(int viewId, int srcId)</nobr>
等同于调用ImageView.setImageResource,从一个 资源中设置图片
<nobr>void</nobr> <nobr><span>setImageViewUri</span>(int viewId, Uri uri)</nobr>
等同于调用ImageView.setImageURI,从URI中设置图 像
<nobr>void</nobr> <nobr><span>setInt</span>(int viewId, String methodName, int value)</nobr>
Call a method taking one int on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setLong</span>(int viewId, String methodName, long value)</nobr>
Call a method taking one long on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setOnClickPendingIntent</span>(int viewId, PendingIntent pendingIntent)</nobr>
Equivalent to calling setOnClickListener(android.view.View.OnClickListener) to launch the provided PendingIntent.
<nobr>void</nobr> <nobr><span>setProgressBar</span>(int viewId, int max, int progress, boolean indeterminate)</nobr>
等同于调用ProgressBar.setMax, ProgressBar.setProgress, and ProgressBar.如果indeterminate为true则进度条的最大和最小进度将会忽略
<nobr>void</nobr> <nobr><span>setShort</span>(int viewId, String methodName, short value)</nobr>
Call a method taking one short on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setString</span>(int viewId, String methodName, String value)</nobr>
Call a method taking one String on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setTextColor</span>(int viewId, int color)</nobr>
等同于setTextColor(int).,设置文本的颜色
<nobr>void</nobr> <nobr><span>setTextViewText</span>(int viewId, CharSequence text)</nobr>
等同于TextView.setText,设置文本内容
<nobr>void</nobr> <nobr><span>setUri</span>(int viewId, String methodName, Uri value)</nobr>
Call a method taking one Uri on a view in the layout for this RemoteViews.
<nobr>void</nobr> <nobr><span>setViewVisibility</span>(int viewId, int visibility)</nobr>
等同于调用View.setVisibility,设置该ID控件的可见性
<nobr>void</nobr> <nobr><span>writeToParcel</span>(Parcel dest, int flags)</nobr>
Flatten this object in to a Parcel.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值