Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8846243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:56:00+00:00 2026-06-14T11:56:00+00:00

I wish to have the default margin for EditText’s be 10dp. Therefore, in my

  • 0

I wish to have the default margin for EditText’s be 10dp. Therefore, in my styles.xml file I set up the following:

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

    <style name="MyTheme" parent="android:style/Theme.NoTitleBar">
        <item name="android:editTextStyle">@style/edit_text_default</item>
    </style>

    <style name="edit_text_default" parent="android:style/Widget.EditText">
        <item name="android:layout_margin">10dp</item>
    </style>

</resources>

Then in AndroidManifest.xml, I set the applications theme to the one I defined:

<application
     android:icon="@drawable/ic_launcher"
     android:label="@string/app_name"
     android:theme="@style/MyTheme" >
...

The “No Title Bar” aspect of the theme is working. However, the default margin for EditText’s is not, it is still filling the parent. Here is my table view:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF" >
    <TableRow>
        <EditText android:hint="@string/last_name" />
    </TableRow>
    <TableRow>
        <EditText android:hint="@string/first_name" />
    </TableRow>
</TableLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:56:02+00:00Added an answer on June 14, 2026 at 11:56 am

    Short Answer: If you are specifying layout_margin in a custom style, this style must be explicitly applied to each individual view that you wish to have the specified margin (as seen in the code sample below). Including this style in a theme and applying it to your application or an activity will not work.

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFF" >
        <TableRow>
            <EditText android:hint="@string/last_name" style="@style/edit_text_default" />
        </TableRow>
        <TableRow>
            <EditText android:hint="@string/first_name" style="@style/edit_text_default" />
        </TableRow>
    </TableLayout>
    

    Explanation: Attributes which begin with layout_ are LayoutParams, or one of its subclasses (e.g. MarginLayoutParams). LayoutParams are used by views to tell their parent ViewGroup how they want to be laid out. Each and every ViewGroup class implements a nested class that extends ViewGroup.LayoutParams. Therefore, LayoutParams are specific to the ViewGroup‘s type. What this means is that while a TableLayout and a LinearLayout may both have layout_margin as one of it’s LayoutParams, they are considered to be completely different attributes.

    So layout_margin is not just general attribute that can be applied anywhere. It must be applied within the context of a ViewGroup that specifically defines it as a valid argument. A view must be aware of the type of its parent ViewGroup when LayoutParams are applied.

    Specifying layout_margin in a style, including that style in a theme, and attempting to apply that theme to an application/activity will result in the layout attributes being dropped, because no ViewGroup parent has been specified yet and so the arguments are invalid. However, applying the style to an EditText view that has been defined with a TableLayout works, because the parent ViewGroup (the TableLayout) is known.

    Sources:

    Android documentation on Layout Parameters.

    Answer given to this question by Android framework engineer and StackOverflow user adamp.

    Also, answer given to this question by StackOverflow user inazaruk.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wish to have the following url(s).. and i'm not sure how i should
I have a default _siteLayout.cshtml file with a call to @RenderBody() in the centre
Part 1: I have a call to layout(:default){|path,wish| wish !~ /rss|atom|json/} but requests to
I wish to have a submit button (for the default form action), and an
I have a file I'm storing within my jar that I use a default
We have typical .NET forms authentication, as per following web.config node. I wish to
I wish to have a page that has a fixed height (without scroll bars).
I wish to have a java-chat on the iphone / ipad. With both, as
I wish to have an If statement in my code, which tests if any
I wish to have a slider similar to they use. http://www.koovs.com/apple-ipod Can anyone suggest

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.