Usage of ?android:attr/ in backwards compatible apps

dsample picture dsample · Jul 8, 2012 · Viewed 11.2k times · Source

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

Answer

sandeep_jagtap picture sandeep_jagtap · Feb 1, 2013

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