背景
Android 4.3 增加了很多对 RTL(从右到左)语言的支持,例如希伯来语和阿拉伯语。
问题
即使有“textDirection”、“layoutDirection”和“gravity”,我也找不到通知生成器的等价物,甚至在兼容性库中也找不到。
这意味着如果同时存在希伯来语和英语单词,则顺序是错误的。例如(为了简单起见,我用英文写):
你得到的不是 "X called Y" ,而是 "Y called X" (假设 " called" 是希伯来语中的一个词),因为字符串应该采用以下格式:
<string name="notification">%1$s called %2$s</string>
注意:X 和 Y 可以是 RTL 或 LTR 字(甚至是偶数)。
要求是,在希伯来语中,右边的词应该是 X ,然后是“被召唤”这个词(当然是希伯来语),然后是左边的 Y 。正如我试图在英语类比示例中展示的那样,情况恰恰相反。
我试过的
一个。我试图搜索文档,我发现我可能需要覆盖布局,但这不是一个好的解决方案。原因:
- 我可能没有使用正确的 Android 样式。
- 对于可能使用不同样式的下一个 Android 版本,这不是未来的证明。
- 它不支持股票代码文本。
湾。我还尝试调查哪些特殊字符会强制文本方向不同,它通过在要显示的文本的开头和结尾添加 '\u200f' 来工作,但它有一些缺陷:
- 它不像其他属性那样灵活。
- 我不确定我使用官方的方式来处理这个问题。
- 每次使用通知时我都需要添加它
- 它对tickerText 根本不起作用。仅适用于通知,即使如此,也不适用于所有情况。
这是一个示例代码:
/** 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 + '\u200f';
}
C。我也可以在字符串中的 '1' 和 '2' 之间切换,但这并不能处理所有情况,而且翻译人员更加困惑。
问题
有什么方法可以让通知生成器正确处理文本(对于通知和 TickerText)?
有什么方法可以在不为通知(或更改字符串)实际制作全新布局的情况下对其进行调整,这可能与 Android 的原生样式不同?
处理这种事情的官方方式是什么?