Java 是否更改remoteView按钮的背景图像?

Java 是否更改remoteView按钮的背景图像?,java,android,android-pendingintent,remoteview,Java,Android,Android Pendingintent,Remoteview,我不太明白这一点。我的活动中有一个按钮,一旦按下该按钮,就会打开一个通知。此自定义通知上有一个按钮。我试图在按下通知后更改背景图像 这是我到目前为止一直在用的东西,运气不好 这是一个服务类,一旦按下“Notification_按钮”,就会调用它。(我有一个调用该类的未决意图) 我认为在custom_layout.xml文件中,您可以给父视图一个id。在代码中使用该父视图的id获取对该父视图的引用,并更改该视图的背景图像以获得所需的结果。因此,任何想知道的人的问题是NotificationComp

我不太明白这一点。我的活动中有一个按钮,一旦按下该按钮,就会打开一个通知。此自定义通知上有一个按钮。我试图在按下通知后更改背景图像

这是我到目前为止一直在用的东西,运气不好

这是一个服务类,一旦按下“Notification_按钮”,就会调用它。(我有一个调用该类的未决意图)


我认为在custom_layout.xml文件中,您可以给父视图一个id。在代码中使用该父视图的id获取对该父视图的引用,并更改该视图的背景图像以获得所需的结果。

因此,任何想知道的人的问题是NotificationCompat.Builder没有被更新,所以无论您最初在哪里拥有它,它需要用remoteView.setInt(R.id.yourDrawable,“setBackgroundResource”,newDrawable)更新;。要么把它扔进一个方法中,然后以这种方式更新它,要么把整个吸盘放到发生更改的类中。

发现NotificationCompat.Builder没有更新,这就是它没有更改的原因-remoteView.setInt(R.id.StartButton_通知,“setBackgroundResource”,sungrey);很好。
  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;
}