android-如何获取textview中的文本语言?

android-如何获取textview中的文本语言?,第1张

概述我在Android消息传递应用程序中有一个textview,我收到了我的android手机的消息,并在textviews中显示了它们,如果文本是波斯语,我想将layout_gravity设置为正确,那么如何检测从uri以下获得的文本语言?Uriuri=Uri.parse("content://sms/");解决方法:有Bidi个班级.此类具有getBa

我在Android消息传递应用程序中有一个textvIEw,我收到了我的androID手机的消息,并在textvIEws中显示了它们,如果文本是波斯语,我想将layout_gravity设置为正确,那么如何检测从uri以下获得的文本语言?

Uri uri = Uri.parse("content://sms/");

解决方法:

有Bidi个班级.此类具有@L_419_2@方法,如果您的文本从左到右,则返回0,否则返回1(如果从右到左).

例:

@OverrIDe    public VIEw getVIEw(final int position, VIEw convertVIEw, VIEwGroup parent) {        VIEwHolder holder;        BIDi bIDi = new BIDi(userList.get(position).getname(), BIDi.DIRECTION_DEFAulT_left_TO_RIGHT);        if(bIDi.getBaseLevel() == 0)            convertVIEw = myInflater.inflate(R.layout.List_add_frIEnds_row, null);        else            convertVIEw = myInflater.inflate(R.layout.List_add_frIEnds_row_mirror, null);

还有另一种方法baseIsleftToRight(),可能最好在if语句中使用.结果与上述相同.

BIDi bIDi = new BIDi(userList.get(position).getname(), BIDi.DIRECTION_DEFAulT_left_TO_RIGHT);if(bIDi.baseIsleftToRight())                convertVIEw = myInflater.inflate(R.layout.List_add_frIEnds_row, null);            else                convertVIEw = myInflater.inflate(R.layout.List_add_frIEnds_row_mirror, null);

SRC:https://stackoverflow.com/a/18008575/797495

public final class BIDiextends Object

This class implements the Unicode BIDirectional Algorithm.

A BIDi object provIDes information on the bIDirectional reordering of
the text used to create it. This is required, for example, to properly
display arabic or Hebrew text. These languages are inherently mixed
directional, as they order numbers from left-to-right while ordering
most other text from right-to-left.

Once created, a BIDi object can be querIEd to see if the text it
represents is all left-to-right or all right-to-left. Such objects are
very lightweight and this text is relatively easy to process.

If there are multiple runs of text, information about the runs can be
accessed by indexing to get the start, limit, and level of a run. The
level represents both the direction and the ‘nesting level’ of a
directional run. Odd levels are right-to-left, while even levels are
left-to-right. So for example level 0 represents left-to-right text,
while level 1 represents right-to-left text, and level 2 represents
left-to-right text embedded in a right-to-left run.

总结

以上是内存溢出为你收集整理的android-如何获取textview中的文本语言?全部内容,希望文章能够帮你解决android-如何获取textview中的文本语言?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1120439.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存