Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

layout_width and layout_height is not applying to edittext from the theme

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" />
like image 661
Pavan Kumar Avatar asked May 30 '13 15:05

Pavan Kumar


2 Answers

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.

like image 148
jonstaff Avatar answered Oct 05 '22 11:10

jonstaff


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"/>
like image 29
TronicZomB Avatar answered Oct 05 '22 11:10

TronicZomB