我有一个应用程序小部件,我想添加视图(TextView等等),RemoteView但它永远不会出现.
这里是代码:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_row_layout);
newView.setTextViewText(R.id.textUser, "1234");
views.addView(views.getLayoutId(), newView);
// Tell the AppWidgetManager to perform an update on the current App Widget
appWidgetManager.updateAppWidget(appWidgetId, views);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
这就是我最终做的事情:
RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_row_layout);
newView.setTextViewText(R.id.textUser, "1234");
ComponentName thisWidget = new ComponentName(this,WidgetProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, newView);
Run Code Online (Sandbox Code Playgroud) 基本上我想做的是将一个自定义的parcelable对象通过intent传递给RemoteViewsService,从而传递给我的RemoteViewsFactory.出于某种原因,这根本不起作用:S每当我尝试这样做时,小部件最终会显示"问题加载小部件"文本.
当我尝试相同的事情,但我没有将它传递给RemoteViewsService,而是将其传递给常规Activity,它完全按预期工作.
我试图在网上找到我的答案,但我一直没有成功,因此我现在发帖在这里希望得到帮助.
我一直试图让这个在我的主程序中运行一段时间.但我无法弄明白.所以我试着将它煮沸,看看我是否在某种程度上做错了什么.我成功地重新创建了这个问题,我重新创建问题的基础来自CommonsGuy的LoremWidget(https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget/LoremWidget)和一个随机的可以说明的例子(http ://prasanta-paul.blogspot.dk/2010/06/android-parcelable-example.htm l)我已经修改过以显示我的问题.(希望我不会遇到麻烦,在这两个链接上使用了代码)
下面是随机文件主机上传的完整代码,以防有人想要测试我正在谈论的内容:http: //www.filedropper.com/remoteviewserviceparcelerrorexample
总结一下我的问题:
为什么我不能将我的parcelable对象(单独或包装在ArrayList中)传递给我的RemoteViewsService?(当相同的代码与Activity一起工作时)
我真的希望有人能够帮助我.现在,在我的主程序中,我将序列化到内部存储,然后从RemoteViewsService再次反序列化,之后我已经阅读了所有内容,这是非常有效的!
编辑:记住,由于某种原因,在我的主程序中,如果我传递一个自定义对象,将ArrayList和Strings设置为null,并将布尔值全部设为false(基本上是对象在创建时的外观),小部件看起来很正常(即没有"问题加载小部件"消息).
编辑:看了一下外观(没有过滤到我正在运行的应用程序)我现在看到一些错误(猜测我最好学会在未获得任何文件的情况下将其全部未过滤:) :):
11-13 17:14:27.268: D/AndroidRuntime(8840): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
11-13 17:14:27.268: D/AndroidRuntime(8840): CheckJNI is ON
11-13 17:14:27.340: D/AndroidRuntime(8840): Calling main entry com.android.commands.pm.Pm
11-13 17:14:27.348: W/ActivityManager(90): No content provider found for permission revoke: file:///data/local/tmp/com.commonsware.android.appwidget.lorem.LoremActivity.apk
11-13 17:14:27.348: W/ActivityManager(90): No content provider found for permission revoke: file:///data/local/tmp/com.commonsware.android.appwidget.lorem.LoremActivity.apk
11-13 17:14:27.356: I/PackageManager(90): Removing non-system package:com.commonsware.android.appwidget.lorem
11-13 17:14:27.360: I/ActivityManager(90): Force stopping package com.commonsware.android.appwidget.lorem uid=10034
11-13 17:14:27.360: I/ActivityManager(90): Killing …Run Code Online (Sandbox Code Playgroud) 我需要制作一个自定义的大型通知,底部有大约3个图像,顶部有图像标题和2个文本视图.
像这样的东西:

上部区域需要看起来与本机通知完全相同,以使它在两者之间有一个很好的过渡.
底部区域是动态的,照片放在那里(使用位图).
一旦我使用自定义视图,它实际上包含整个布局,包括上部区域.
我想到了两个解决方案:
为了创建位图,我可以使用这样的东西:
final int widthScreen = getResources().getDisplayMetrics().widthPixels;
final int width = Math.min(widthScreen, (int) convertDpToPixels(this, 256));
final Bitmap outputBitmap = Bitmap.createBitmap(width, width / 3, Config.ARGB_8888);
final Canvas canvas = new Canvas(outputBitmap);
final int[] imagesResIds = { R.drawable.pic1, R.drawable.pic2, R.drawable.pic3 };
final Paint paint = new Paint();
for (int i = 0; i < 3; ++i) {
final Bitmap b = BitmapFactory.decodeResource(getResources(), imagesResIds[i]);
canvas.drawBitmap(b, null, new Rect(i * (width / 3), …Run Code Online (Sandbox Code Playgroud) android android-custom-view android-layout android-notifications remoteview
int mColor = 0xff00ff00;
remoteView.setInt(R.id.framelayout1, "setBackgroundResource", android.R.color.white);
Run Code Online (Sandbox Code Playgroud)
如何使用mColor设置颜色?
我想在运行时将以线性布局排列的文本视图添加到我的小部件中.我这样做:
LinearLayout l = new LinearLayout(context);
for (int i = 0; i < 10; i++) {
TextView t = new TextView(context);
t.setText("Hello");
l.addView(t); }
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
RemoteViews view = new RemoteViews (context.getPackageName(), l.getId());
views.addView(R.layout.main, view);
Run Code Online (Sandbox Code Playgroud)
但是当我添加小部件时,我得到一个问题加载小部件错误.似乎RemoteViews接收构造的视图id作为参数有问题.但我无法引用XML资源,因为它们是在运行时创建的.在运行时填充RemoteViewswith 的正确方法是什么TextViews?
我正在制作一个小部件,您可以在其中指定文本大小
controles.setTextViewTextSize(R.id.LblMsg,TypedValue.COMPLEX_UNIT_SP,textSize);
我正在使用android 4.1
android:minSdkVersion ="8"android:targetSdkVersion ="16"
问题是它在android 4.1中正常工作,但在任何其他版本(ICS,姜饼等)显示强制关闭.
java.lang.NoSuchMethodError:android.widget.RemoteViews.setTextViewTextSize
如果我删除使用"setTextViewTextSize"的代码行,应用程序将完美运行.
我找不到有关此错误原因的信息.
我感谢任何帮助.
问候
之前已经问过这个问题,但没有一个答案帮助我发布我的案例.
我正在尝试使用布局文件构建自定义通知.但是我收到以下错误:
android.app.RemoteServiceException:从包com.eswaraj.app.eswaraj发布的错误通知:无法展开RemoteViews:StatusBarNotification(pkg = com.eswaraj.app.eswaraj user = UserHandle {0} id = 8888 tag = null score = 0:通知(pri = 0 contentView = com.eswaraj.app.eswaraj/0x7f030052 vibrate = null sound = null defaults = 0x0 flags = 0x0 kind = [null]))
我的布局文件是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left">
<com.makeramen.RoundedImageView
android:id="@+id/nImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/profile_image"
android:padding="15dp"
android:scaleType="fitCenter"
app:riv_corner_radius="30dip"
app:riv_border_width="2dip"
app:riv_border_color="#333333"
app:riv_mutate_background="true"
app:riv_oval="true"/>
<TextView
android:id="@+id/nTitle"
android:text="eSwaraj: Your voice is heard"
android:layout_toRightOf="@+id/nImage"
android:paddingTop="12dp"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/nMessage"
android:layout_below="@+id/nTitle"
android:layout_toRightOf="@+id/nImage"
android:text="Your comaplaint …Run Code Online (Sandbox Code Playgroud) 在我的AppWidgetProvider中,我执行以下操作:
@Override
public void onReceive(Context ctx, Intent intent) {
final String action = intent.getAction();
if (action.equals(NEXTPAGE_ACTION)) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(ctx);
RemoteViews rv = new RemoteViews(ctx.getPackageName(), R.layout.widget_layout);
rv.setViewVisibility(R.id.page1, View.GONE);
rv.setViewVisibility(R.id.page2, View.VISIBLE);
final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
appWidgetManager.updateAppWidget(appWidgetId, rv);
}
}
Run Code Online (Sandbox Code Playgroud)
虽然我正在通过updateAppWidget更新布局,但更改并未真正反映在UI上.什么可能出错?非常感谢!
我正在尝试在onUpdate中的窗口小部件布局中的图像视图中设置图像,但图像未更新
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
Log.i(TAG, "onUpdate called");
for (int appWidgetId : appWidgetIds)
{
Bitmap bitmap=ImageUtils.getBitmap(context, appWidgetId);
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget);
remoteView.setImageViewBitmap(R.id.imgView,bitmap);
appWidgetManager.updateAppWidget(appWidgetId, remoteView);
}
}
Run Code Online (Sandbox Code Playgroud)
小部件的xml布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
清单文件
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.demo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WidgetConfig"
android:label="@string/app_name" >
<intent-filter>
<action
android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<receiver
android:name="BasicWidgetProvider"> …Run Code Online (Sandbox Code Playgroud) android android-widget remoteview appwidgetprovider android-appwidget
我想用大型动画gif图像制作自定义通知.所以我找不到解决方案来解决这个问题.因为我只能使用RemoteView来进行客户布局. 不使用RemoteView创建自定义Android通知
但RemoteView只支持一些基本视图.
https://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
我怎样才能做到这一点?
android ×10
remoteview ×10
widget ×3
colors ×1
gif ×1
image ×1
java ×1
parcel ×1
textview ×1
visibility ×1