Search code examples
javaandroidpush-notificationandroid-xmlremoteview

Android set rtl support on push notification


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;

Solution

  • 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.