我不太明白这一点。我的活动上有一个按钮,一旦按下它就会打开一个通知。此自定义通知上有一个按钮。我正在尝试更改通知的背景图片,一旦它被按下。
这是我到目前为止使用过的,但没有成功的方法。
这是一个服务类,一旦按下"notifcation_Button“就会被调用。(我有一个调用这个类的待定意图)
public class newService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("newService", "Newservice");
RemoteViews remoteView = new RemoteViews(getPackageName(), R.layout.custom_layout); //this is my custom notification
remoteView.setInt(R.id.StartButton_Notification, "setBackgroundColor", R.drawable.sungrey);
remoteView.setInt(R.id.StartButton_Notification, "setBackgroundResource", sungrey);
remoteView.setImageViewResource(R.id.StartButton_Notification, R.drawable.sungrey);
return START_NOT_STICKY;
}发布于 2019-10-19 02:14:09
因此,对于任何想知道的人来说,问题是NotificationCompat.Builder没有更新,所以无论您最初在哪里使用它,它都需要使用remoteView.setInt(R.id.yourDrawable,"setBackgroundResource",newDrawable);进行更新。要么将其放入一个方法中并以这种方式更新它,要么将整个吸盘放入发生更改的类中。
发布于 2019-10-10 12:02:50
我想在custom_layout.xml文件中你可以给父视图一个id。在代码中使用其id获取对父视图的引用,并更改该视图的背景图像以获得所需的结果。
https://stackoverflow.com/questions/58311456
复制相似问题