【问题标题】:layout_width and layout_height is not applying to edittext from the themelayout_width 和 layout_height 不适用于主题中的edittext
【发布时间】:2013-05-30 15:51:33
【问题描述】:

下面我在主题中添加了EditText 样式。我也添加了宽度和高度。所以我从我的edittext 视图中删除了android:layout_widthandroid:layout_height。但它说的是错误。如果我添加宽度和高度,它工作正常。有什么区别。主题是否不适用于我的 edittext 视图?

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

我的编辑文本视图

 <EditText android:hint="Username" />

【问题讨论】:

  • 您的样式属性在哪里?
  • 是 lint 还是编译错误?

标签: android android-layout android-theme android-styles


【解决方案1】:

您的styles.xml 必须包含

&lt;resources xmlns:android="http://schemas.android.com/apk/res/android"&gt; 在顶部。

如果此文件是自动生成的或您自己制作的,则有时会忘记此属性。

【讨论】:

    【解决方案2】:

    你需要将样式应用到EditText:

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

    编辑:根据您的评论,我认为这就是您想要的:

    <EditText android:hint="Username"
        android:layout_height="48dp"
         android:layout_width="match_parent"/>
    

    【讨论】:

    • 这就是风格。但我需要从主题而不应用样式。
    • 但是我已经在上面的样式中添加了高度和宽度。为什么你又在更新的代码中添加了?不是重复的吗?
    • 如果您不想应用样式,那么您需要执行第二个选项,因为您没有应用样式,因此您没有将高度和宽度属性应用于 EditText。跨度>
    • ​​@drawable/edittextboxtrue 已经存在了。这两个是在没有向editText添加样式的情况下应用的。但是为什么宽度和高度不适用?
    猜你喜欢
    • 2011-04-16
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 2016-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多