Android 在推送通知上设置 rtl 支持
Android set rtl support on push notification
我的目标是在推送通知上设置 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;
通知布局由Android系统自动处理。如果图标在 RTL 模式下位于左侧,这是有原因的,并且每个通知在设备上都会像这样显示。即使您设法更改应用通知的布局,您的用户也会对不一致的通知布局感到困惑。
您可以在 Material Design Guidelines 中阅读有关通知布局的更多信息。
我的目标是在推送通知上设置 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;
通知布局由Android系统自动处理。如果图标在 RTL 模式下位于左侧,这是有原因的,并且每个通知在设备上都会像这样显示。即使您设法更改应用通知的布局,您的用户也会对不一致的通知布局感到困惑。
您可以在 Material Design Guidelines 中阅读有关通知布局的更多信息。