21

I had a working app on 2.1 and above until I tried to cleanup my initial layout with a theme of styles. Now the app won't even start with the "You must supply a layout_height attribute" failure message pointing to my first EditText View in the layout.

Why can I not move the 'layout_height=30dp" that was working fine on every EditText into an ... item name="android:layout_height">30dp< ... in a style referred to via my theme?

Virtually all my other style effects I abstracted out like this are working just fine.

[It won't surprise me to learn this must be some styled override to the LinearLayout, not the EditText's. OR that its got to be a styled item for the View, not the Widget. I don't know.]

Ideas? Anyone? What is the obvious thing overlooked? THANKS in advance for any suggestions!

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<application    android:label="xxx"
    android:icon="@drawable/xxx" >

<activity   android:name="DataEntry"
    android:label="xxx"
    android:theme="@style/xxx_theme.A" >
...

xxx_theme.A.xml

<style name="xxx_theme" parent="@android:Theme" >
  <item name="android:windowNoTitle">true</item>
</style>

<style name="xxx_theme.A" >
  <item name="android:textViewStyle">@style/xxx_TextView_widget</item>
  <item name="android:editTextStyle">@style/xxx_EditText_widget</item>
  <item name="android:checkboxStyle">@style/xxx_CheckBox_widget</item>
  <item name="android:radioButtonStyle">@style/xxx_Radio_widget</item>
</style>

<style name="xxx_EditText_widget" parent="@android:style/Widget.EditText" >
  <item name="android:textSize">9dp</item>
  <item name="android:layout_height">30dp</item>
  <item name="android:paddingLeft">8dp</item>
  <item name="android:paddingTop">1dp</item>
  <item name="android:paddingBottom">1dp</item>
  <item name="android:textColorHint">@color/texthint</item>
  <item name="android:singleLine">true</item>
  <item name="android:selectAllOnFocus">true</item>
  <item name="android:inputType">textNoSuggestions</item>
</style>
...
peterh
  • 11,875
  • 18
  • 85
  • 108
Randy
  • 213
  • 2
  • 5

2 Answers2

9

You have <item name="android:layout_height">30dp</item> but no android:layout_width in your style.

You need both.

Jon Willis
  • 6,993
  • 4
  • 43
  • 51
  • No cigar. Actually, different cigar. With both specified in the style and removed from the first EditText, it now complains (crashes) with "... must specify layout_width ...". I do thank you guys for giving me an idea outside-the-box of what I had been thinking, tho. I'm going to have to see if this went away after 2.1. – Randy Apr 13 '11 at 01:21
  • Well, @Jon, it behaves identically in the 2.1, 2.2, and 2.3.3 emulators. With android:layout_height and android:layout_width removed from the EditText in main.xml, and set as attributes to the Widget.EditText style, it still crashes pointing to my first instance of an EditText view as missing layout_width. – Randy Apr 13 '11 at 04:04
  • If I style= the individual EditText's in the layout, pointing to the same style I was hoping they'd inherit through theming my activity, the EditText's work. Not so sure I want to call that a 'fix', but it makes the definition of the original problem different. Its some kind of theme-inheritance issue, IMHO. – Randy Apr 13 '11 at 13:26
  • 1
    need help from the moderators. Your answer was most definitely accurate and helpful, but the original problem statement turns out to be misguided. – Randy Apr 14 '11 at 12:48
  • you can try and edit your question, but i'm not sure what else you can do :P – Jon Willis Apr 14 '11 at 16:02
  • Have you solved this? I have the same issue and cannot find solution. – ivy_the Oct 13 '15 at 10:46
1

Check out my answer here. It most likely has to do with a missing attribute in your styles.xml file.

Community
  • 1
  • 1
jonstaff
  • 2,672
  • 2
  • 19
  • 18
  • Tried this (in Android Studio 2.2 RC2). You were right in that the xmlns header was missing, but adding it and doing a clean build didn't affect the issue. :( – David Lord Sep 15 '16 at 04:26