2013-05-30 38 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">

如果此文件是自動生成的,或者您自己創建了該文件,那麼此屬性有時會被遺忘。

相關問題