2012-04-20 7 views

答えて

11

使用がまたがる:

TextView textView = (TextView)findViewById(R.id.mytextview01); 
Spannable WordtoSpan = new SpannableString("partial colored text");   
WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 2, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
textView.setText(WordtoSpan); 
+0

は 'パラメータが欠落しているsetText'されていますしてください?私はそれも 'BufferType'を取ると思います。 –

1

android:textColor、EditText xmlでこのプロパティを設定します。

15

あなたはこのようにandroid:textColorを追加することによって、テキストの色を変更することができます。

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textColor="#f00" /> 
8

私は、これは非常に古い質問です知っているが、これが最初だったので、私はしばらくの間です私は将来の読者がそれを得るために答えを加えたいと思います。

textColor以外の多くの属性を持つstyles.xmlファイルに独自のカスタムスタイルを作成し、EditTextに適用することができます。

は、のstyles.xmlでこれを追加

<style name="MyEditTextstyle"> 
    <item name="android:textColor">@color/dark_blue</item> 
    <item name="android:background">@drawable/my_custom_edittext_bg</item> 
    <item name="android:layout_marginTop">5dp</item> 
    <item name="android:layout_marginBottom">5dp</item> 
    //many more per requirement 
</style> 

そして単にシンプル

<EditText 
    style="@style/MyEditTextstyle" //here 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:hint="Item Name" 
    android:padding="10dp" > 
    <requestFocus /> 
</EditText> 

、右、とのEditTextにこのスタイルを適用します。 :)重要な部分は、必要に応じて、これ以上のEditTextに同じものを適用できます。 :)

1

XMLレイアウトから:

私たちは以下のようにandroid:textColorを追加することにより、EditTextテキストの色を変更することができます。

<EditText 
    android:id="@+id/myEditText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="Your Name" 
    android:textColor="#FF0000" 
</EditText> 

Javaクラスから:

我々はできますアドビによって実際にEditTextテキストの色を変更以下のようにNG方法EditText.setTextColor()

EditText myEditText = (EditText)findViewById(R.id.myEditText); 
myEditText.setTextColor(Color.RED); 
関連する問題