Android设置rtl支持推送通知

时间:2017-06-16 12:44:50

标签: java android push-notification android-xml remoteview

我的目标是在推送通知上设置rtl支持。我的通知切换文本方向但不是布局的位置。例如,图标始终在左侧,标题在右侧,文本在左侧。我的猜测是所有都应该是左或右。我试图创建自定义xml,但问题是我无法在远程视图上设置layoutDirection。使用的代码:

标准通知:

mNotification = new NotificationCompat.Builder(context)
    .setContentTitle(contentTitle)
    .setContentText(contentText)
    .setSmallIcon(appIcon)
    .setContentIntent(contentIntent)
    .setSound(soundUri)
    .setAutoCancel(true)
    .setWhen(started)
    .build();

自定义xml:

RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.my_id);
                contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher);
                contentView.setTextViewText(R.id.title, contentTitle);
                contentView.setTextViewText(R.id.text, "Text "));

mNotification.contentView = contentView;

1 个答案:

答案 0 :(得分:2)

通知布局由Android系统自动处理。如果图标在RTL模式下位于左侧,则有一个原因,并且每个通知都会在设备上显示。即使您设法更改应用程序通知的布局,您的用户也会对不一致的通知布局感到困惑。

您可以在Material Design Guidelines中了解有关通知布局的更多信息。