2

I'm trying to present Hebrew text in m TextView.

I have read here I need to change the font from default android's to a hebrew supporting one.

I have tried few solutions, but none of them worked:

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

    titleTextView.setText(mTitles[position]);
    

or:

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

here is my 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>

any idea how to solve this?

is there a way to define default font per application? per Layout?

Community
  • 1
  • 1
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • 2
    Hebrew in a TextView works well "right out of the box". Maybe there are issues with the BIDI, but generally it displays it good. – Sean Sep 26 '13 at 17:20
  • that was it! I have added my xml. how can I fix this to be seen as: image and right to two lines of text: title, date? – Elad Benda Sep 26 '13 at 17:38

2 Answers2

0

Hebrew in a TextView works well "right out of the box". Maybe there are issues with the BIDI, but generally it displays it good.

Regarding you second question, how can you set up a layout to be used when using hebrew, take a look at this: RTL Languages support in android and resource qualifiers

Community
  • 1
  • 1
Sean
  • 5,176
  • 2
  • 34
  • 50
  • what would you advise if my text for some items is english and for some in hebrew? How would I determine the writing direction? – Elad Benda Sep 26 '13 at 17:51
  • Android will check the first character in the text and determines according to the character language it's direction. If the TextView is not setting a text gravity - you will see the effect automatically. – Sean Sep 26 '13 at 17:53
  • Sean, What do you mean "issues with BIDI"? @EladBenda how did you solve it? Thanks – bentzy Mar 11 '14 at 13:38
  • @Benny, BIDI is the determination of what direction should the text be formatted. Android determines what's the direction according to the first character in the text. If it's in RTL Language, the entire text will be aligned right, if it's a LTR language - aligned left. – Sean Mar 12 '14 at 08:59
  • Thanks @Sean! What do you mean by issues with BIDI? How do I debug it? I don't see the font I've chose in Hebrew, but in English the custom font does work. – bentzy Mar 12 '14 at 10:07
  • @Benny The BIDI has nothing to do with the actual Hebrew characters and their appearance as far as I understand. Are you sure you font supports hebrew? Try displaying the hebrew with the regular Android font, does that work? – Sean Mar 12 '14 at 14:45
0

Base on my experience, if you specify on the TextView android:singleLine="true" it will not show Hebrew characters, it's definitely a bug in the android source code and might be fixed in a later release.

based on that I believe that android:lines="1" is what is causing the issue for you.