【问题标题】:android TextView doesn't show hebrew fontsandroid TextView 不显示希伯来字体
【发布时间】:2013-09-26 17:14:05
【问题描述】:

我正在尝试在 m TextView 中显示希伯来语文本。

我已阅读here 我需要将字体从默认的 android 更改为支持希伯来语的字体。

我尝试了几个解决方案,但都没有奏效:

    Typeface font= Typeface.createFromAsset(mContext.getAssets(), "fonts/Raanana.ttf");
    titleTextView.setTypeface(font); 

    titleTextView.setText(mTitles[position]);
    

或:

    titleTextView.setText(Html.fromHtml(mTitles[position]));

这是我的 xml:

<ImageView
    android:id="@+id/todo_row_image"
    android:layout_width="50dp"
    android:layout_height="30dp"
    android:layout_marginBottom="32dp"
    android:layout_marginLeft="21dp"
    android:contentDescription="my image" />

<TextView
    android:id="@+id/todo_row_title"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="6dp"
    android:lines="1"
    android:text="@+id/titleTextView"
    android:layout_toRightOf="@id/todo_row_image"
    android:textSize="12sp" >
</TextView>

<TextView
    android:id="@+id/todo_row_date"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/todo_row_title"
    android:layout_marginTop="6dp"
    android:lines="1"
    android:text="@+id/dateTextView"
    android:textSize="12sp" >

</TextView>

知道如何解决这个问题吗?

有没有办法为每个应用程序定义默认字体?每个布局?

【问题讨论】:

  • TextView 中的希伯来语“开箱即用”效果很好。可能是 BIDI 有问题,但总体上显示它很好。
  • 就是这样!我已经添加了我的 xml。我怎样才能解决这个被视为:图像和两行文本的权利:标题,日期?

标签: java android eclipse fonts


【解决方案1】:

TextView 中的希伯来语“开箱即用”效果很好。可能是 BIDI 有问题,但总体上显示它很好。

关于第二个问题,如何设置使用希伯来语时要使用的布局,看看这个: RTL Languages support in android and resource qualifiers

【讨论】:

  • 如果我的一些项目的文本是英文而一些是希伯来语,你会建议什么?如何确定写作方向?
  • Android 会检查文本中的第一个字符,并根据字符语言确定它的方向。如果 TextView 没有设置文本重力 - 你会自动看到效果。
  • 肖恩,“BIDI 的问题”是什么意思? @EladBenda 你是怎么解决的?谢谢
  • @Benny,BIDI 是决定文本应该格式化的方向。 Android根据文本中的第一个字符确定方向。如果是 RTL 语言,则整个文本将右对齐,如果它是 LTR 语言 - 左对齐。
  • 谢谢@Sean! BIDI 的问题是什么意思?我该如何调试它?我没有看到我在希伯来语中选择的字体,但在英语中,自定义字体确实有效。
【解决方案2】:

根据我的经验,如果您在 TextView 上指定 android:singleLine="true" 它将不会显示希伯来字符,这肯定是 android 源代码中的一个错误,可能会在以后的版本中修复。

基于此,我认为 android:lines="1" 是导致您出现问题的原因。

【讨论】:

    猜你喜欢
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    • 2011-09-12
    • 2011-07-30
    相关资源
    最近更新 更多