14

I'm trying to make my ICS (API level 15) app compatible with Gingerbread (API level 10), and I'm getting InflateException Error inflating class <Unknown> for any layout XML that has an ?android:attr/ attribute. If I comment out these attributes I can compile and run the app, but then it, of course, looks aweful.

I'd rather not duplicate all of the items from android.R.attr that I'm using, but at the moment I'm lost as to another way to do it.

I'm using ActionBarSherlock to get the ActionBar working, and I don't seem to be using anything else that requires the support library (although I've included it during the process of trying to figure this out), it's just these theme-based resources that I'm stuck on.

Some of the theme resources I'm using are:

?android:attr/textColorSecondaryInverse ?android:attr/textAppearanceLarge ?android:attr/dividerVertical ?android:attr/selectableItemBackground ?android:attr/textAppearanceMedium ?android:attr/dividerVertical ?android:attr/dividerHorizontal

pawelzieba
  • 16,082
  • 3
  • 46
  • 72
dsample
  • 444
  • 1
  • 4
  • 14
  • Unfortunatelly dividerHorizontal style is not defined in ABS (My version is 4.1.0). Maybe because it covers only the styles used by the ActionBar). And actually dividerVertical is defined. It is very frustrating that ABS theme does not cover all the original styles! – WindRider Jan 30 '13 at 22:18
  • 1
    @WindRider do not mislead others. Check [2 lines](https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml#L348-L349) in Android sources. And this is simple 1x1 nine patch png. Same does ActionBarSherlock. But it doesn't add alias `dividerHorizontal` – mente Aug 16 '13 at 09:43

3 Answers3

12

to use styles from API 11 Specifically android:attr/textAppearanceMedium ?android:attr/dividerVertical ?android:attr/dividerHorizontal

The easiest way is to use following code where ever your required

<!-- For Horizontal Line-->
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:background="#aaa"
android:layout_alignParentTop="true"/>

<!-- For Vertical Line-->

<View
android:id="@+id/VerticalLine"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip"
android:background="#aaa"/>
sandeep_jagtap
  • 1,484
  • 2
  • 17
  • 24
  • Perfect solution. But why do you need marginLeft and marginRight? The attribute android:divider="?android:attr/dividerHorizontal" spans the entire width of the screen. – IgorGanapolsky Aug 29 '13 at 04:30
  • I wanted horizontal line with that margin. Its not necessary to have any margin. You can remove it. – sandeep_jagtap Aug 29 '13 at 05:33
11

As is in the documentation some styles are in higher API. For example:

  • dividerVertical since API 11
  • dividerHorizontal since API 11

? mark is used to reference style in current theme.

To deal with your problem you can:

  • use styles from API 11, but put them to values-v11 folder and support styles for older versions in values using custom values or different attributes from older API.
  • copy necessary styles from ICS
  • don't use these styles
  • use custom styles

It depends what's your aim. First suggestion makes sense when native style of application is important for you.
If you want to have Holo style everywhere then there is no way than copy it and use as a one style for all platforms.
Take a look at this project: https://github.com/Prototik/HoloEverywhere

Community
  • 1
  • 1
pawelzieba
  • 16,082
  • 3
  • 46
  • 72
  • Is there somewhere with an example of your first suggestion? I think referencing the native styles on v11+ would be best, but I'm not sure what I'd need to put in the different `values` and `values-v11` style definitions to pass onto the normal Holo resources for v11 and define specifically (copying the Holo resource, I guess) for the compatibility version. – dsample Jul 08 '12 at 14:02
3

Please check android support v7 - appcompat project. It has many themes and attributes for backwards compatibility (attr/dividerHorizontal also)

http://developer.android.com/tools/support-library/features.html#v7-appcompat

To use v7 support you must import it as an Android lib project and reference to it from you project. It also contains v4 support so you may want to remove v4 support in your libs folder :) Good luck!!

khigianguyen
  • 139
  • 2
  • 8
  • I don't think this is possible. The attr exists but there's no guarantee that a drawable for the vertical divider. – Tim Kist Nov 14 '13 at 21:48
  • 1
    Drawables (including vertical divider) are also packed in v7 support project, along with xml attr values :). – khigianguyen Nov 15 '13 at 09:23
  • 1
    I beg your pardon. I couldn't see the vertical divider drawable. It's in res/drawable-mdpi/abc_list_divider_holo_(dark/light).9.png – Tim Kist Nov 15 '13 at 09:36
  • I can't :(. I've tried removing the vote but it's locked. I tried to edit it but it would work :(. Sorry. – Tim Kist Nov 19 '13 at 10:33