Question

Following is the code to display EditText,

 <EditText
     android:id="@+id/editStartingPoint"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:background="@null"
     android:gravity="left|center_vertical"
     android:hint="@string/StartingPointHint"
     android:inputType="text"
     android:maxLength="8"
     android:padding="10dp"
     android:text=""
     android:textColor="@color/login_lbl"
     android:textSize="@dimen/settings_list_font_size" />

In Activity file, onCreate() method,

edtStartPoint = (EditText) findViewById(R.id.editStartingPoint);
edtStartPoint.setText ( Html.fromHtml( "<small><i>" + "This should be in Italic" + "</i></small>" ));

I also tried,

edtStartPoint.setTypeface( null, Typeface.ITALIC );

I have also tried to set textStyle="italic" in my .xml file

but the problem is that Text is not displaying in Italic style, What could be the problem ? Please help me out.

Edit : It is also not showing Text in bold format. xml preview it is showing fine, but when I run the code in real device Samsung S7562, it is displaying a normal text only

Was it helpful?

Solution

Edit:

Adding android:textstyle to your xml should work.

In case if you are using custom font ensure that your font have italic style. From the documentation of the setTypeface(Typeface) method:

Sets the typeface and style in which the text should be displayed. Note that not all Typeface families actually have bold and italic variants, so you may need to use setTypeface(Typeface, int) to get the appearance that you actually want.

If your custom do support italic, try this, mTextView.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC)

OTHER TIPS

I solve the issue by Writting following lines before then ending } of onCreate() method

edtStartPoint.setHint( R.string.StartingPointHint );

String.xml

<string name="StartingPointHint"><i>This is italic</i></string>

Just put in your EditText xml attribute :

android:textStyle="italic"

Depends what you're looking at, but there are also some devices (notably from Samsung) that don't show italic text correctly. See here for some work-arounds: Samsung devices supporting setTypeface(Typeface.Italic)?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top