我可以在RemoteViews中使用WebView吗?

时间:2020-10-17 01:42:52

标签: java android android-layout android-fragments

我在Android应用中创建了一个通知。

我使用以下代码:

RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);
RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_small);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
  .setSmallIcon(R.mipmap.ic_launcher)
  .setCustomContentView(notificationLayout)
  .setCustomBigContentView(notificationLayoutExpanded)

      .setStyle(new NotificationCompat.BigTextStyle()
              .bigText("Much longer text that cannot fit one line..."))
      .setPriority(NotificationCompat.PRIORITY_DEFAULT);

在我的notification_small.xml中,我写道:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    
    >

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

但是,当显示我的自定义通知时,我的应用程序崩溃了(我没有日志)。

如果我将WebView替换为TextView,则我的应用选择正常。

0 个答案:

没有答案