6

Below i have added EditText style in theme. I have added width and height also. So i removed android:layout_width and android:layout_height from my edittext view. But it is saying error. If i add width and height it is working fine. What is the difference. Is theme is not applying to my edittext view?

<style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="android:editTextStyle">@style/custom_EditTextStyle</item>
</style>
<style name="custom_EditTextStyle" parent="@android:style/Widget.EditText">
         <item name="android:background">@drawable/edittextbox</item>
         <item name="android:singleLine">true</item>
         <item name="android:layout_width">fill_parent</item>
         <item name="android:layout_height">48dp</item>
    </style>

My editText view

 <EditText android:hint="Username" />
Nompumelelo
  • 929
  • 3
  • 17
  • 28
Pavan Kumar
  • 1,616
  • 5
  • 26
  • 38

2 Answers2

6

Your styles.xml must contain

<resources xmlns:android="http://schemas.android.com/apk/res/android"> at the top.

If this file was auto-generated or you made this file yourself, this attribute is sometimes forgotten.

jonstaff
  • 2,672
  • 2
  • 19
  • 18
2

You need to apply the style to the EditText:

 <EditText android:hint="Username"
  style="@style/custom_EditTextStyle" />

Edit: based on your comment I think this is what you want:

<EditText android:hint="Username"
    android:layout_height="48dp"
     android:layout_width="match_parent"/>
TronicZomB
  • 8,667
  • 7
  • 35
  • 50
  • This is style. but i need from theme without applying the style. – Pavan Kumar May 30 '13 at 21:38
  • 1
    But i already added height and width in the above style. Why again you added in your updated code? isnt it duplicate? – Pavan Kumar May 30 '13 at 21:48
  • If you want don't want to apply style then you need to do the second option because you aren't applying the style therefore you are not applying the height and width attributes to the EditText. – TronicZomB May 30 '13 at 23:21
  • 3
    @drawable/edittextbox true already there. These two are applying without adding style to editText. But why width and height are not applying? – Pavan Kumar May 31 '13 at 08:13