2013-11-22 30 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