2013-11-22 31 views
1

我正在嘗試爲我的應用程序編寫一般的style.xml。Android:使用一般風格應用邊距不起作用

我想我所有的EditText的意見有一定的風格,所以我做了這樣的事情:

<!-- Base application theme. --> 
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <item name="android:editTextStyle">@style/App_EditTextStyle</item> 
    </style> 

    <style name="App_EditTextStyle"> 
     <item name="android:background" >#ff0000</item> 
     <item name="android:textColor">#00ff00</item> 
     <item name="android:layout_marginLeft">50dip</item> 
     <item name="android:height">50dip</item> 
    </style> 

在清單我應用的主題:

<application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/MyAppTheme" > 

這裏是樣品佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/main_layout"> 

    <EditText 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/editText" 
     android:text="Test" /> 

    <EditText 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/editText2" 
     android:text="Test2" /> 
</LinearLayout> 

一切工作正常,除了保證金。出於某種原因,它不適用,我必須手動添加到EditText。我錯過了什麼嗎?

+0

參見[這個答案](http://stackoverflow.com/a/13365288/2052936) – igork

回答

0

如果你想這樣做,所有的EditText小部件,然後將此到LinearLayout標籤:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/main_layout" 
    style="@style/MyAppTheme"> 
+2

1.這是整個應用程序的主題,所以我將它應用於清單文件中。 2.正如我所提到的,這些風格是應用的(紅色bg,高度:50dp),只有不適用的是邊距。 – Tomer

+0

而不是'application'標籤中的android:theme =「@ style/MyAppTheme」,你試過'style =「@ style/MyAppTheme」' – ChuongPham