1

I'm trying to write a general style.xml for my app.

I want all my EditText views to have certain styling, so I've done something like this:

<!-- 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>

In the manifest i apply the theme:

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

and here is the sample layout:

<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>

Everything is working fine except for the margin. For some reason it does not apply and i have to add it manually to the EditText. Am i missing something?

AJ.
  • 4,526
  • 5
  • 29
  • 41
Tomer
  • 17,787
  • 15
  • 78
  • 137

1 Answers1

1

If you want to do it for all EditText widgets, then apply this to the LinearLayout tag:

<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">
ChuongPham
  • 4,761
  • 8
  • 43
  • 53
  • 2
    1. This is a theme for the entire app, so i apply it in the manifest file. 2.As i mentioned, the styles are applying (red bg, height: 50dp) only thing that is not applying is the margin. – Tomer Nov 22 '13 at 13:06
  • Instead of `android:theme="@style/MyAppTheme"` in the `application` tag, did you try `style="@style/MyAppTheme"` – ChuongPham Nov 22 '13 at 13:20