Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android自定义通知RemotView不使用任何样式_Java_Android_Xml_Android Layout_Android Notifications - Fatal编程技术网

Java Android自定义通知RemotView不使用任何样式

Java Android自定义通知RemotView不使用任何样式,java,android,xml,android-layout,android-notifications,Java,Android,Xml,Android Layout,Android Notifications,我尝试用远程视图创建一个自定义notfification,远程视图可以扩展并具有不同的文本视图和按钮。这很好,但布局中的大多数字段都不使用样式。 在花了4个多小时进行搜索并尝试修复后,我发现谷歌代码中唯一一个描述此错误的问题: https://code.google.com/p/android开发者预览/issues/detail?id=1894 有人知道如何解决这个问题或绕过这个问题吗 我尝试使用我的风格或android风格,没有任何风格。。。 它看起来像是样式,这取决于字段的位置,因为在扩展

我尝试用远程视图创建一个自定义notfification,远程视图可以扩展并具有不同的文本视图和按钮。这很好,但布局中的大多数字段都不使用样式。 在花了4个多小时进行搜索并尝试修复后,我发现谷歌代码中唯一一个描述此错误的问题:

https://code.google.com/p/android开发者预览/issues/detail?id=1894

有人知道如何解决这个问题或绕过这个问题吗

我尝试使用我的风格或android风格,没有任何风格。。。 它看起来像是样式,这取决于字段的位置,因为在扩展版本中,第一个字段接受样式

我的测试代码

创建通知

       NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        // set the view layout
        RemoteViews remoteViewsNotification = new RemoteViews(this.getPackageName(),
                R.layout.notification_non_expanded);
        remoteViewsNotification.setTextViewText(R.id.notification_test_field_1, "non-expanded");

        RemoteViews remoteViewsExpandedNotification = new RemoteViews(this.getPackageName(),
                R.layout.notification_expanded);
        remoteViewsExpandedNotification.setTextViewText(R.id.notification_test_field_1, "expanded");


        // create a new notification intent and set the actions
        Intent notificationIntent = new Intent(this, TrainingInProgress.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        // Create the notification and set all values
        Notification notification = new NotificationCompat.Builder(this)
                .setContent(remoteViewsNotification)
                .setSmallIcon(sportsIconId)
                .setContentIntent(pendingIntent)
                .setOngoing(true).build();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            notification.bigContentView = remoteViewsExpandedNotification;
        }

        notificationManager.notify(notifyId, notification);
XML通知\u未\u扩展

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <TextView
        android:id="@+id/notification_test_field_1"
        style="@style/TextAppearance.StatusBar.EventContent.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 1" />

    <TextView
        android:id="@+id/notification_test_field_2"
        android:layout_below="@id/notification_test_field_1"
        style="@style/TextAppearance.StatusBar.EventContent.Line2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 2" />


    <TextView
        android:id="@+id/notification_test_field_3"
        style="@style/TextAppearance.StatusBar.EventContent.Time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 3"
        android:layout_below="@+id/notification_test_field_1"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />


    <TextView
        android:id="@+id/notification_test_field_4"
        style="@style/TextAppearance.StatusBar.EventContent.Info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 4"
        android:layout_below="@+id/notification_test_field_2"
        android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



    <TextView
        android:id="@+id/notification_test_field_1"
        style="@style/mainHeadlineBigTextStyleDark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 1" />

    <TextView
        android:id="@+id/notification_test_field_2"
        android:layout_below="@id/notification_test_field_1"
        style="@style/mainHeadlineBigTextStyleDark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 2" />


    <TextView
        android:id="@+id/notification_test_field_3"
        style="@style/mainHeadlineBigTextStyleDark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 3"
        android:layout_below="@+id/notification_test_field_1"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />


    <TextView
        android:id="@+id/notification_test_field_4"
        style="@style/mainHeadlineBigTextStyleDark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 4"
        android:layout_below="@+id/notification_test_field_2"
        android:layout_centerInParent="true" />

</RelativeLayout>

扩展的XML通知

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <TextView
        android:id="@+id/notification_test_field_1"
        style="@style/TextAppearance.StatusBar.EventContent.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 1" />

    <TextView
        android:id="@+id/notification_test_field_2"
        android:layout_below="@id/notification_test_field_1"
        style="@style/TextAppearance.StatusBar.EventContent.Line2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 2" />


    <TextView
        android:id="@+id/notification_test_field_3"
        style="@style/TextAppearance.StatusBar.EventContent.Time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 3"
        android:layout_below="@+id/notification_test_field_1"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />


    <TextView
        android:id="@+id/notification_test_field_4"
        style="@style/TextAppearance.StatusBar.EventContent.Info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 4"
        android:layout_below="@+id/notification_test_field_2"
        android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



    <TextView
        android:id="@+id/notification_test_field_1"
        style="@style/mainHeadlineBigTextStyleDark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 1" />

    <TextView
        android:id="@+id/notification_test_field_2"
        android:layout_below="@id/notification_test_field_1"
        style="@style/mainHeadlineBigTextStyleDark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 2" />


    <TextView
        android:id="@+id/notification_test_field_3"
        style="@style/mainHeadlineBigTextStyleDark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 3"
        android:layout_below="@+id/notification_test_field_1"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />


    <TextView
        android:id="@+id/notification_test_field_4"
        style="@style/mainHeadlineBigTextStyleDark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="Test Field 4"
        android:layout_below="@+id/notification_test_field_2"
        android:layout_centerInParent="true" />

</RelativeLayout>

我用于测试的样式

<style name="mainHeadlineBigTextStyleDark">
    <item name="android:gravity">center</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">20sp</item>
    <item name="android:textColor">@color/mainHeadlineBigTextColorDark</item>
</style>


 <color name="mainHeadlineBigTextColorDark">#747474</color>

居中
大胆的
20便士
@颜色/主标题行BigTextColorDark
#747474

又花了几个小时,我发现了错误

如果通过xml提示字段为TextView提供文本:

    android:hint="Test Field 1"
并且不要覆盖或设置文本

        remoteViews.setTextViewText(R.id.title, "TEXT");
然后,在选定的xml中,样式未应用,文本保持白色


因为我正在使用虚拟文本创建布局,所以我还没有意识到这一点…

在花费了几个小时之后,我发现了错误

如果通过xml提示字段为TextView提供文本:

    android:hint="Test Field 1"
并且不要覆盖或设置文本

        remoteViews.setTextViewText(R.id.title, "TEXT");
然后,在选定的xml中,样式未应用,文本保持白色


因为我正在使用虚拟文本创建布局,所以我还没有意识到这一点…

设置RelativeLayout的背景色可能会有帮助我已经尝试过了,但没有帮助。这可能只是一个解决办法,将其更改为深色以使其可读,但我想使用常见的设计..设置RelativeLayout的背景色可能有帮助我已经尝试过了,但没有帮助。这可能只是一个解决办法,将其更改为深色以使其可读,但我想使用通用设计。。