remoteviews
2011-04-22 14:58:14|分类: Android 杂记 |标签:intremoteviewsviewidvoidlayout |字号大中小订阅
如何实例化一个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.
|