0

I'm trying to style text inEditText. I've managed to stytle the EditText itself, but not its content. How can I go about changing the font weight, font color, style etc for text held inside the EditText?

This is how I style the EditText view:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingBottom="10dp"
    android:paddingLeft="42dp"
    android:paddingRight="10dp"
    android:paddingTop="10dp">
    <item android:bottom="3dp">
        <bitmap
            android:gravity="center_vertical|left"
            android:src="@drawable/ic_games_black_24dp" />
        <shape android:shape="rectangle">
            <stroke
                android:width="1dp"
                android:color="#37474f" />
        </shape>
    </item>
</layer-list>

Then I call it:

EditText editText = new EditText( mContext );
editText.setHint(" Find");
editText.setWidth(555);
editText.setBackgroundResource(R.drawable.add_new_bag_dr);

What is the best way to go about it? What options do I have?

UPDATE

How can I attach a style defined in an XML to a View?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Program-Me-Rev
  • 6,184
  • 18
  • 58
  • 142
  • Check this https://stackoverflow.com/questions/3078081/setting-global-styles-for-views-in-android – Farmer Jul 13 '17 at 05:54

1 Answers1

1

you can use the following:

editText.setTextColor("set the color you want");

Define your custom style in style.xml and then use

editText.setTextAppearance(R.style.yourCustomStyle);

Hope it helps!!!

sumit
  • 1,047
  • 1
  • 10
  • 15