Question

Working in Eclipse, I am trying to put some italics text onto a layout. The problem is, that when I am setting android:textStyle="italic", the text disappears. (The height of content becomes 0 and the whole TextView becomes invisible.) Bold works OK. I have tried every typeface, but the result is the same.

On the device it shows itself in italics OK. But the layout is very complicated and its design without seeing it becomes very complicated, too.

Here is the TextView

     <TextView
          android:id="@+id/smallEpgNextProgramTime"
          android:layout_width="200dp"
          android:layout_height="wrap_content"
          android:maxLines="1"
          android:ellipsize="end"
          android:layout_margin="10dp"
          android:gravity="left|top"
          android:textSize="35dp"
          android:typeface="monospace"
          android:textStyle="italic"
          android:text="12:00-13:11"
    />      

Android version is 2.3.3. Eclipse version is 2.6.

It is even worse. If I leave italics there, after some changes of layout view to graphics and back to text, Eclipse works slower and slower and hangs up the PC. So, I have to put it as "normal" in layout and to set textStyle by code. A bad bug it is!

Was it helpful?

Solution

I think its an android platform issue.

Look at Issue 22867: Incorrect layout preview when ITALIC text style used

It doesn't show up on the layout's graphical representation but works correctly when you build and run the app.

Update: If you want to preview for designing xml layout then just use

android:typeface="serif"

In this android:textStyle="italic" works. And text will displayed in italic style in graphical layout editor.

Its only works for this serif typeface.

OTHER TIPS

 you can use this 

 TextView txtView;
 txtView=(TextView)findViewById(R.id.smallEpgNextProgramTime);
 txtView.setText(Html.fromHtml("Restaurant <i><b>Hello</b></i>"));

What u wrote is 100% correct if you want to write in code you can use this..

            textView.setTypeface(null, Typeface.ITALIC);
            textView.setText(editText.getText().toString());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top