layout_width和layout_height不适用于主题的edittext

问题描述 投票:4回答:2

下面我在主题中添加了EditText样式。我也增加了宽度和高度。因此,我从android:layout_width视图中删除了android:layout_heightedittext。但这是在说错误。如果我添加宽度和高度,它工作正常。有什么不同。主题是否不适用于我的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视图

 <EditText android:hint="Username" />
android android-layout android-theme android-styles
2个回答
6
投票

您的styles.xml必须包含

<resources xmlns:android="http://schemas.android.com/apk/res/android">在顶部。

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


2
投票

您需要将样式应用于EditText

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

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

<EditText android:hint="Username"
    android:layout_height="48dp"
     android:layout_width="match_parent"/>
© www.soinside.com 2019 - 2024. All rights reserved.