Android在推送通知上设置rtl支持 [英] Android set rtl support on push notification

查看:66
本文介绍了Android在推送通知上设置rtl支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

标准通知:

  mNotification =新的NotificationCompat.Builder(上下文).setContentTitle(contentTitle).setContentText(contentText).setSmallIcon(appIcon).setContentIntent(contentIntent).setSound(soundUri).setAutoCancel(true).setWhen(开始).建造(); 

和自定义xml:

  RemoteViews contentView =新的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模式下图标位于左侧,则可能是由于这种原因,并且每个通知的显示方式都与设备上的显示相同.即使您设法更改应用程序通知的布局,您的用户也会因通知布局不一致而感到困惑.

您可以在材料设计指南中了解有关通知布局的更多信息./p>

My target is to set rtl support on push notifications. My notification switch text direction but not places of layouts. For example icon is always in left, title is in right and text is in left. My guess is that all should be left or right. I have tried to create custom xml, but the problem is that I cannot set layoutDirection on remote view. Code used:

Standard notification:

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

And custom 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;

解决方案

Notification layout is handled by the Android system automatically. If the icon is on the left in RTL mode, there's a reason for that, and every notification is displayed like that on the device. Even if you manage to change the layout for your app's notification, your users would be confused with the inconsistent notification layouts.

You can read more about notification layouts in the Material Design Guidelines.

这篇关于Android在推送通知上设置rtl支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆