layout_width and layout_height is not applying to edittext from the theme

坚强是说给别人听的谎言 提交于 2021-01-27 05:26:26

问题


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" />

回答1:


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.




回答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"/>


来源:https://stackoverflow.com/questions/16840635/layout-width-and-layout-height-is-not-applying-to-edittext-from-the-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!