问题
I am using an actionbar and navigation drawer in my project. Using appcompat v7 and v4.
I have added the appcompat v7 WITH resources.
The following is my textview for the navigation drawer list taken straight from the android sample app found at Creating a Navigation Drawer
The bottom three lines all cause my application to fail, it builds okay, but I get a force close and I am not sure how to solve the problem. I don't understand why the attributes are not being found, considering I added the appcompat with its resources. Or are they not valid with the appcompat or something?
MinSDK Version is 10 and at which the code fails. Above API 10 the code works fine.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#fff"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
回答1:
I had same issue. As i understand older apis haven't predefined textAppearanceListItemSmall, activatedBackgroundIndicator and listPreferredItemHeightSmall. So if you need you can specify your own values or remove this lines and rely on your luck.
回答2:
You can use the values as defined in the compatibility library: It specifies all except the background, which I have chosen listChoiceBackgroundIndicator, although you might play with others as well.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#fff"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="?attr/listPreferredItemHeightSmall"/>
来源:https://stackoverflow.com/questions/18250096/navigation-drawer-using-appcompat-v7-issues-with-androidattr-tag