Change background color of edittext in android
Here the best way
First : make new xml
file in res
/drawable
name it rounded_edit_text
then paste this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#F9966B" />
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" />
</shape>
Second: in res/layout copy and past following code (code of EditText
)
<EditText
android:id="@+id/txtdoctor"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/rounded_edit_text"
android:ems="10" >
<requestFocus />
</EditText>
one line of lazy code:
mEditText.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
I create color.xml file, for naming my color name (black, white...)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#ffffff</color>
<color name="black">#000000</color>
</resources>
And in your EditText, set color
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdsadasdasd"
android:textColor="@color/black"
android:background="@color/white"
/>
or use style in you style.xml:
<style name="EditTextStyleWhite" parent="android:style/Widget.EditText">
<item name="android:textColor">@color/black</item>
<item name="android:background">@color/white</item>
</style>
and add ctreated style to EditText:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdsadasdasd"
style="@style/EditTextStyleWhite"
/>