2013-05-30 37 views
4

下面我已添加主题中的EditText样式。我增加了宽度和高度。所以我从edittext视图中删除了android:layout_width和android:layout_height。但它是在说错误。如果我添加宽度和高度,它工作正常。有什么不同。主题不适用于我的edittext视图吗?layout_width和layout_height不适用于从主题编辑文本

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

你的风格属性在哪里? Blackbelt

+0

它是一个皮棉还是编译错误? –

回答

2

您需要的样式应用到EditText

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

编辑:基于您的评论我觉得这是你想要什么:

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

这是风格。但我需要从主题而不应用风格。 –

+0

我更新了我的答案。 – TronicZomB

+1

但我已经在上面的样式中添加了高度和宽度。为什么你再次添加更新后的代码?是不是重复? –

6

您的styles.xml必须包含顶部的

<resources xmlns:android="http://schemas.android.com/apk/res/android">

如果此文件是自动生成的,或者您自己创建了该文件,那么此属性有时会被遗忘。

相关问题