Android below 4.2 how to set layoutDirection to be RTL
You won't be able to. It was added to in API Level 17 which is 4.2 so the older versions do not support it.
How to handle mixed RTL & LTR languages in notifications?
OK, found an answer, based on this, this and this.
For the above case:
%1$s called %2$s
In order to change it correctly to Hebrew, you need to add the special character "\u200f" , as such:
<string name="notification">%1$s התקשר ל %2$s</string>
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (VERSION.SDK_INT >= VERSION_CODES.O) {
String id = "my_channel_01";
CharSequence name = "channelName";// getString(R.string.channel_name);
String description = "channelDesc";//getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel channel = new NotificationChannel(id, name, importance);
channel.setDescription(description);
channel.enableLights(true);
channel.setLightColor(Color.RED);
channel.enableVibration(true);
channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
notificationManager.createNotificationChannel(channel);
}
Intent resultIntent = new Intent(this, MainActivity.class);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
String[] names1 = new String[]{"משה", "Moses"};
String[] names2 = new String[]{"דוד", "David"};
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
String name1, name2;
name1 = names1[i];
name2 = names2[j];
name1 = "\u200f" + name1 + "\u200f";
name2 = "\u200f" + name2 + "\u200f";
final String text = getString(R.string.notification, name1, name2);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this, "TEST")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(text)
.setContentIntent(resultPendingIntent)
.setChannelId("my_channel_01")
.setContentText(text);
int notificationId = i*2+j;
notificationManager.notify(notificationId, mBuilder.build());
}
}
}
You can also check if the current locale is RTL, before choosing to use this solution. Example:
public static boolean isRTL() {
return
Character.getDirectionality(Locale.getDefault().getDisplayName().charAt(0)) ==
Character.DIRECTIONALITY_RIGHT_TO_LEFT;
}
The result:
Android: RTL support - digits embedded in a right to left sentence (Hebrew)
Is RTL support in Android still
immature?
If by "immature" you mean "nonexistent", then, yes, it is immature. Each Android SDK release lists the supported languages, and you will notice that RTL languages are not among them.
Related Topics
How to Determine If Network Type Is 2G, 3G or 4G
Change Toolbar Color in Appcompat 21
How to Add a Library (Android-Support-V7-Appcompat) in Intellij Idea
Selector on Background Color of Textview
How to Generate a Thumbnail from a Video Url in Android
Upload Photo to Facebook with Facebook Android Sdk in Android
Backup and Restore SQLite Database to Sdcard
Securityexception: Caller Uid Xxxx Is Different Than the Authenticator's Uid
Android Studio:How to Uninstall APK (Or Execute Adb Command) Automatically Before Run or Debug
How to Fix "Unexpected Element <Queries> Found in <Manifest>" Error
How to Create a Circular (Endless) Recyclerview
Is There a Listener for When the Webview Displays It's Content
How to Retrieve Style Attributes Programmatically from Styles.Xml
Listview with Add and Delete Buttons in Each Row in Android
Connectivitymanager.Connectivity_Action Deprecated
How to Set Emoji by Unicode in a Textview