Set a consistent theme for all the editTexts in An

2019-02-25 06:38发布

I have finished making my app. Now, I want to reset all my editTexts to have the layout width as fill parent instead of wrap content.

android:layout_width="fill_parent"

while currently all my editTexts are

android:layout_width="wrap_content"

Is there any way i can do this in a style xml file, instead of individually in each layout? I currently have this as my styles.xml

<style name="AppTheme" parent="android:Theme.Light">  
    <item name="android:fontFamily">Verdana</item>
    <item name="android:editTextStyle">@style/EditTextStyle</item>
</style>

<style name="EditTextStyle" parent="@android:style/Widget.EditText">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:textColor">#808080</item>
</style>

But i'm getting an exception saying that layout_width must be specified. This is my exception:

07-15 11:13:34.872: E/AndroidRuntime(1195): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.passwordkeeper.ui/com.passwordkeeper.ui.ActivityLogin}: java.lang.RuntimeException: Binary XML file line #29: You must supply a layout_width attribute.

Any easy way out or do i have to change the attribute in all my editText's individually?

7条回答
可以哭但决不认输i
2楼-- · 2019-02-25 07:30

define the style attribute for all EditText like below:

   <EditText
    android:id="@+id/editText1"
    android:layout_height="wrap_content"
    style="@style/EditTextStyle">
查看更多
登录 后发表回答