0

远程视图自定义通知未显示进度条。如果我使用水平样式但不显示圆形进度条,它可以工作。

有人可以帮我解决这个问题吗?

主要活动-

 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
 import android.widget.RemoteViews;

 public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.noti);
    remoteViews.setProgressBar(R.id.progressBar2,100,50,false);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setCustomBigContentView(remoteViews)
            .setPriority(2);
    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);

    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);

    remoteViews.setImageViewResource(R.id.image,R.mipmap.ic_launcher);
    remoteViews.setTextViewText(R.id.text,"sdasdas");
    mBuilder.setContent(remoteViews);
    mBuilder.setCustomBigContentView(remoteViews);

    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(3453453, mBuilder.build());


           }
 }

Noti.xml -

        <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal" android:layout_width="match_parent"
       android:layout_height="128dp">


  <ProgressBar
  style="?android:attr/progressBarStyleLarge"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/progressBar2"
  android:layout_weight="1" />

      </LinearLayout>
4

0 回答 0