Android 4.3增加了对RTL(从右到左)语言的大量支持,例如希伯来语和阿拉伯语.
即使有"textDirection","layoutDirection"和"gravity",我找不到通知构建器的等价物,甚至在兼容性库中也找不到.
这意味着如果一起有希伯来语和英语单词,则顺序错误.例如(为简单起见,我用英文写):
而不是"X叫Y",你得到"Y叫X"(假设"被称为"是希伯来语中的一个单词),因为该字符串应该采用以下格式:
<string name="notification">%1$s called %2$s</string>
Run Code Online (Sandbox Code Playgroud)
注意:X和Y可以是RTL或LTR字(和偶数).
要求是在希伯来语中,右边的单词应该是X,然后单词"被叫"(当然是希伯来语),然后是左边的Y. 正如我试图在英语类比例子中展示的那样,情况正好相反.
一个.我试图搜索文档,我发现的是我可能需要覆盖布局,但这不是一个好的解决方案.原因:
湾 我还试图调查哪些特殊字符会强制文本方向不同,并且通过在显示的文本的开头和结尾添加'\ u200f'来起作用,但它有一些缺陷:
这是一个示例代码:
/** prepares a string to be shown in a notification, so that it will be shown even on RTL languages */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static String prepareNotificationText(final Context context, final String text) {
if (VERSION.SDK_INT < VERSION_CODES.JELLY_BEAN_MR1)
return text;
final boolean isRTL = context.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
if (!isRTL)
return text;
return '\u200f' + text …Run Code Online (Sandbox Code Playgroud) android hebrew android-notifications android-support-library rtl-language