how to code custom style for a view in android

In this blog post, I would like to show how to code Custom Style for a View in Android. In this example, i’m just using an edit text only, but you can use any view.

1. Create a new project File -> Android Project. On activity_main.xml copy paste this code:

<RelativeLayout xmlns:android=""
android:layout_height="match_parent" >

android:text="@string/hello_world" >

<requestFocus />


2. Now open your styles.xml file under res/values folder and copy paste this code:


<style name="AppBaseTheme" parent="android:Theme.Light">

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:editTextStyle">@style/edittext</item>

<style name="edittext" parent="@android:style/Widget.EditText">
<item name="android:textColor">#26CE61</item>

Now open your layout graphical view and you can find the text color is customed.



custom_style edittext


Tips to Remember always:

Some might ask, why don’t i simply use this code snippet ?


Well, this might be the simplest way of assigning text  color for an edit text, but consider if your app contains  few edit texts where all edit text need to be in same design constant, then changing a color for all edit text makes your work complex. In this situation, custom style will help you up in easy way.


Hope this helpful. Your valuable comments are always welcomed. It will help to improve my post and understanding.

durga chiranjeevi

durga chiranjeevi

I'm currently working as Android developer at Energy Alternatives India. Interested in Application and Game development.
durga chiranjeevi

Leave a Reply

Your email address will not be published. Required fields are marked *

займ на карту онлайн круглосуточно