翻译自定义通知字符串

问题描述

我的应用支持 2 种语言,希伯来语和英语。我正在尝试使用 2 个操作按钮制作自定义通知,但通知描述是希伯来语而不是英语(我猜它使用我手机的认系统语言),除了按钮,它们工作正常。

但是,当我不使用自定义通知时,一切都很好(最后一盒代码)。

自定义通知代码

NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_launch,getString(R.string.launch),activityPendingIntent);
NotificationCompat.Action action2 = new NotificationCompat.Action(R.drawable.ic_cancel,getString(R.string.stop),servicePendingIntent);


        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID);
        Notification notification = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID)
        .setContentTitle(getString(R.string.letherkNow))
        .setContentText(getString(R.string.running_in_the_backgroud))
        .addAction(action)
        .addAction(action2)
        .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
        .setCustomContentView(notificationLayout)
        .setColorized(true)
        .setColor(getColor(R.color.foreGroundBackgroundColor))
        .setPriority(notificationmanager.IMPORTANCE_HIGH)
        .setCategory(Notification.CATEGORY_SERVICE)
        .setSmallIcon(R.drawable.applogo)
        .build();

自定义通知 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="60dp">

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/title"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="5dp"
        android:layout_toEndOf="@+id/image"
        android:text="@string/running_in_the_backgroud"
        android:textAlignment="center"
        android:textColor="#008066"
        android:textSize="16sp"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="0dp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="9dp"
        android:layout_toEndOf="@+id/image"
        android:text="@string/title"
        android:textAlignment="center"
        android:textColor="#008066"
        android:textSize="18sp"
        android:textStyle="bold" />

</RelativeLayout>

正常工作正常的通知

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID);
Notification notification = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID)
        .setContentTitle(getString(R.string.letherkNow))
        .addAction(action)
        .addAction(action2)
        .setContentText(getString(R.string.launch))
        .setColor(getColor(R.color.foreGroundBackgroundColor))
        .setPriority(notificationmanager.IMPORTANCE_HIGH)
        .setCategory(Notification.CATEGORY_SERVICE)
        .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.applogo))
        .setSmallIcon(R.drawable.applogo)
        .build();

谢谢!

编辑: 我还在 build.gradle 中检查了 resConfigs:

defaultConfig {
    resConfigs "en-rUS","iw-rIL"
}

解决方法

解决方案:

所以经过长时间的研究,因为我将 RemoteView 用于自定义通知,所以我使用了 setTextViewText 并添加了以下内容:

mRemoteView.setTextViewText(R.id.customnotificationtext,getString(R.string.runninginbackground));

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...