2013-08-01 91 views
0

以下是顯示的EditText代碼,爲什麼我無法在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" /> 

在活動文件,onCreate()方法,

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

我也試過,

edtStartPoint.setTypeface(null, Typeface.ITALIC); 

我還試圖設置textStyle="italic"在我的.xml文件中

但是p問題是文本不以斜體顯示,可能是什麼問題?請幫助我。

編輯:它也不以粗體格式顯示文本。 XML預覽它顯示正常,但是當我運行在真實設備三星S7562的代碼,它顯示的是一個普通的文本只

+0

[如何讓你的EditText斜體?](http://stackoverflow.com/questions/14950850/how-to-make-your-edittext-italicized) – CodingIntrigue

+0

分享您完整的XML文件 – Sri

回答

0

編輯:

添加android:textstyle到你的XML應該工作。

如果您使用自定義字體,請確保您的字體具有italic樣式。從setTypeface(字體)方法的文檔:

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.

如果您的自定義做支持斜體,試試這個, mTextView.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC)

+0

我做了,但它不工作:( – Vigbyor

+0

檢查您的自定義字體,因爲我在這篇文章中說過。希望這會幫助你:) –

0

只要把你的EditText XML屬性:

android:textStyle="italic" 
+0

我的可能重複也做了這部分,但它不工作:( – Vigbyor

+0

你使用自定義字體? –

+0

是............. – Vigbyor

1

我解決通過書面方式,然後結束}之前以下行的問題onCreate()方法的

edtStartPoint.setHint(R.string.StartingPointHint); 

String.xml

<string name="StartingPointHint"><i>This is italic</i></string> 
相關問題