我需要知道允许我设置RemoteView权重的代码.
我尝试使用此代码,但这不起作用:
RemoteViews remoteViews = new RemoteViews(c.getPackageName(), R.layout.notification);
remoteViews.setInt(R.id.ll_notification, "setWeight", 12);
Run Code Online (Sandbox Code Playgroud)
有办法做到这一点?非常感谢....
我创建了一个通知方法,如下所示:
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification;
notification = new Notification(R.drawable.messageicon, "You have a new message",
System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification);
view.setImageViewResource(R.id.image, R.drawable.ic_launcher);
view.setTextViewText(R.id.title, "New Message");
view.setTextViewText(R.id.text, message);
notification.contentView = view;
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.contentIntent = activity;
notificationManager.notify(0, notification);
Run Code Online (Sandbox Code Playgroud)
我想在状态栏上添加一个按钮,单击该按钮时,应显示一个弹出窗口.任何帮助将受到高度赞赏.
如何从通知中的按钮控制音乐播放器,以及如何从通知中收听按钮操作
notifications android audio-player android-music-player remoteview
当我的StackedWidget视图只是一个textview时,它显示在启动器屏幕上,但是有一个更复杂的布局(A RelativeLayout,imageview,textviews)它不会显示任何内容
设置RemoteViews有什么我需要知道的吗?
widget_item.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_item"
android:layout_width="270dp"
android:layout_height="150dp">
<ImageView
android:id="@+id/timelineCellImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:onClick="onClick"
android:scaleType="centerCrop"
android:src="@drawable/bottom_grey_gradient"
/>
<LinearLayout
android:id="@+id/timelineCellTextHolder"
android:layout_width="match_parent"
android:layout_height="@dimen/fifty_dp"
android:layout_alignBottom="@id/timelineCellImage"
android:layout_alignLeft="@id/timelineCellImage"
android:background="@drawable/rounded_edges_bottom_dark"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginLeft="@dimen/five_dp"
android:layout_marginRight="@dimen/five_dp"
android:layout_marginTop="@dimen/ten_dp"
android:layout_weight=".5"
android:ellipsize="end"
android:gravity="bottom"
android:lines="1"
android:text="Test"
android:textColor="@color/white"
android:textSize="@dimen/twelve_sp"
android:textStyle="bold" />
<TextView
android:id="@+id/subheading"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="@dimen/ten_dp"
android:layout_marginLeft="@dimen/five_dp"
android:layout_marginRight="@dimen/five_dp"
android:layout_weight=".5"
android:ellipsize="end"
android:gravity="top"
android:lines="1"
android:text="Subtest"
android:textColor="@color/white"
android:textSize="@dimen/twelve_sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
StackWidgetService.java $getViewAt(int)
public RemoteViews getViewAt(int position) {
// position will always range from 0 to getCount() - 1.
RemoteViews rv = …Run Code Online (Sandbox Code Playgroud) 我在我的开发AppWidget根据Android的文档,装我的光标onCreate(),并在重新加载它onDataSetChanged(),一切工作正常,直到我把我的一些断点RemoteViewsService.RemoteViewsFactory,并惊奇地发现,onDataSetChanged()是始终调用后调用onCreate(),这使我的光标装载两次,当第一创建.我在Android 4.4.3上.
根据Api doc,
public abstract void onDataSetChanged()
在API级别11中添加
在远程适配器上触发notifyDataSetChanged()时调用.这允许RemoteViewsFactory通过更新任何内部引用来响应数据更改.注意:在此方法中可以安全地同步执行昂贵的任务.在此期间,旧数据将显示在窗口小部件中.
似乎只能通过自己手动调用notifyDataSetChanged()来触发此调用.
但是根据Appwidget指南,
在onCreate()中,您可以为数据源设置任何连接/光标.繁重的工作,例如下载或创建内容等,应该推迟到onDataSetChanged()或getViewAt().在此呼叫中花费超过20秒将导致ANR.
通过说延期,是否暗示onDataSetChanged()将被称为后onCreate()?我不太确定......但它确实说我应该把光标放在里面onCreate().
我自己尝试调查此问题,但是可用的源代码正在使用,Binder因此远程调用者仍然未知,因此我无法检查其来源.
你有什么主意吗?
我试图listview在小部件的帮助下制作动态remoteview,因为我想在小部件中使用这个listview应用程序图标.我想显示来自所有应用程序明智的应用程序的传入通知.我想创建常设通知列表,当用户点击列表视图中的应用程序图标时,将显示该特定通知.我正在使用API 19获取所有通知并且也成功但我不知道如何Listview在小部件中创建Remoteview和使用drawables(Icons).
我有一个必须应用过滤器的ImaveViewon a 。RemoteView当我不在的时候,RemoteView这就是我所做的,而且效果很好:
Drawable icon = getResources().getDrawable(R.drawable.icon);
icon.setColorFilter(color, PorterDuff.Mode.SRC_IN);
image.setImageDrawable(icon);
Run Code Online (Sandbox Code Playgroud)
似乎RemoteView没有办法让我设置不是资源的可绘制对象。我该怎么做呢?
谢谢。
android android-widget android-notifications remoteview android-remoteview
我正在为我的应用程序创建自定义通知布局。
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_icon)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setCustomContentView(notificationLayoutCollapsed)
.setOngoing(playing)
.setCustomBigContentView(notificationLayoutExpanded)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setContentIntent(pendingIntent);
Run Code Online (Sandbox Code Playgroud)
我的通知布局没有内部填充或边距,但它显示通知的边距(蓝色通知周围的白色粗边框)。
请提出解决此问题的方案。
- - 回答 - - -
罪魁祸首是以下这一行
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
Run Code Online (Sandbox Code Playgroud)
DecoratedCustomViewStyle 为通知提供边框
在我的小部件中,我使用以下内容将项目 (R.layout.widget_item) 动态添加到我的主小部件布局中定义的 LinearLayout:
//-- Main widget layout
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_design);
//-- Add to main layout
RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_item);
views.addView(R.id.view_container, newView);
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何在 newView 上动态设置“android:layout_weight”属性?
我正在实现一个app小部件,我希望能够在小部件布局中更改单个视图的属性,而无需RemoteViews从头开始重建所有内容,这涉及加载XML等,在某些情况下不需要.有没有办法说"在当前窗口小部件布局中由特定ID标识的视图上更新属性X"?我已经看到班上有一种partiallyUpdateAppWidget方法,AppWidgetManager但是我无法理解,也不是为了这个目的,也不是必须如何使用它.你能帮助我或指向一个有用的链接或例子吗?