Make editText hint italic?

邮差的信 提交于 2019-12-23 17:17:11

问题


How do you do this in xml, can you?

I see this in a related question for the java code to do it, check length is 0 and:

EditText.setText(Html.fromHtml("<small><i>" + "Text Hint Here" + "</i></small>"));

But can you just do it from xml?

EDIT:

<EditText
        android:id="@+id/term_entry"
        android:layout_width="500dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@+id/scrllyout"
        android:imeOptions="actionNone|flagNoExtractUi"
        android:inputType="text|textImeMultiLine"
        android:singleLine="true"
        android:hint="Enter Command"
        android:textStyle="italic"
        android:textColorHint="#30AAAAAA"
        />

回答1:


Better use java code.use Typeface. Put your font file in assest folder. And then write below code.

italic = Typeface.createFromAsset(getAssets(), "Your font file"); 
editText.setTypeface(italic);  



回答2:


try like this in XML

<EditText
    android:id="@+id/editText1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"  
    android:hint="hint" 
    android:textStyle="italic" > 
</EditText>

to make hint use android:hint="hint" and for making italic word use like this android:textStyle="italic"

updated:

here is the XML try this, I have tested in my notebook works fine.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >


<EditText
    android:id="@+id/term_entry"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/scrllyout"
    android:hint="Enter Command"
    android:imeOptions="actionNone|flagNoExtractUi"
    android:inputType="text|textImeMultiLine"
    android:singleLine="true"
    android:textColorHint="#ffffff"
    android:textStyle="italic" />

</LinearLayout>


来源:https://stackoverflow.com/questions/14648959/make-edittext-hint-italic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!