问题描述
我的应用支持 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();
<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));