user900329
user900329

Reputation:

android : how to change the style of edit text?

I'm trying to change the style of the EditText? Is it possible to achieve that? If so I'll appreciate being told about it, otherwise what alternative ways are available.

Upvotes: 14

Views: 64057

Answers (3)

Nilesh Savaliya
Nilesh Savaliya

Reputation: 666

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="android:colorBackground">@color/windowBackground</item>
    <item name="android:textColor">@color/textColor</item>
    <item name="colorAccent">@color/colorAccent</item>
    //apply Button style
    <item name="android:editTextStyle">@style/editTextStyle</item>
</style>

//Button Style
<style name="editTextStyle" parent="@style/Widget.AppCompat.EditText">
    <item name="android:textColor">@color/colorWhite</item>
    <item name="android:background">@color/colorPrimary</item>
    <item name="android:textSize">24sp</item>
    <item name="android:paddingTop">10dp</item>
    <item name="android:paddingBottom">10dp</item>
</style>

Upvotes: 4

Mario Lenci
Mario Lenci

Reputation: 10542

You can use the attribute style="@style/your_style" that is defined for any widget.

To define your style you have to create a file called style.xml in the values folder (i.e. \res\values\styles.xml) and use the following syntax:

<style name="You.EditText.Style" parent="@android:style/Widget.EditText">
    <item name="android:textColor">@color/your_color</item>
    <item name="android:gravity">center</item>
</style>

The attribute parent="@android:style/Widget.EditText" is important because it will ensure that the style being defined extends the basic Android EditText style, thus only properties different from the default style need to be defined.

Upvotes: 29

Force
Force

Reputation: 6392

Yes, it is definitely possible. See http://developer.android.com/guide/topics/ui/themes.html (Raghu already postet that link) for more details.

You can also but a background in it, see this post: http://www.anddev.org/tutorial_buttons_with_niceley_stretched_background-t4369.html It only covers buttons, but it is exactly the same for edittexts.

Upvotes: 0

Related Questions