有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java翻译自定义通知字符串

我的应用程序支持两种语言,希伯来语和英语。我试图用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:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:app="http://schemas.安卓.com/apk/res-auto"
    xmlns:tools="http://schemas.安卓.com/tools"
    安卓:id="@+id/layout"
    安卓:layout_width="match_parent"
    安卓:layout_height="60dp">

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

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

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

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

    <TextView
        安卓:id="@+id/title"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignParentTop="true"
        安卓:layout_alignParentEnd="true"
        安卓:layout_marginTop="9dp"
        安卓:layout_toEndOf="@+id/image"
        安卓:text="@string/title"
        安卓:textAlignment="center"
        安卓:textColor="#008066"
        安卓:textSize="18sp"
        安卓: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();

谢谢大家!

编辑: 我还检查了构建中的重新配置。格拉德尔:

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

共 (1) 个答案

  1. # 1 楼答案

    解决方案:

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

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