使用的android:ATTR /在向后兼容的应用程序应用程序、android、ATTR

2023-09-05 08:46:23 作者:柳桥无复水

我试图让我的ICS(API级别15)姜饼(API等级10)的应用程序兼容,我得到 InflateException错误充气类<未知> 任何布局XML,有一个安卓?ATTR / 属性。如果我注释掉这些属性,我可以编译和运行应用程序,但随后,当然,看起来aweful。

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.

我宁愿不复制所有从 android.R.attr 我使用的物品,但此刻我是迷路了,以另一种方式要做到这一点。

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.

我用ActionBarSherlock拿到动作条的工作,而我似乎并没有使用其他任何需要的支持库(虽然我试图算出这个过程中包括它),它只是这些主题为基础的资源我卡上。

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:

?机器人:ATTR / textColorSecondaryInverse ?机器人:ATTR / textAppearanceLarge ?机器人:ATTR / dividerVertical ?机器人:ATTR / selectableItemBackground ?机器人:ATTR / textAppearanceMedium ?机器人:ATTR / dividerVertical ?机器人:ATTR / dividerHorizo​​ntal

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

推荐答案

由于是在的文档一些风格是较高的API。例如:

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

dividerVertical ,因为API 11 dividerHorizo​​ntal ,因为API 11 dividerVertical since API 11 dividerHorizontal since API 11

标记用来引用风格在当前的主题。

? mark is used to reference style in current theme.

要处理你的问题,您可以:

To deal with your problem you can:

从API 11使用的风格,但把它们值-V11 值的文件夹和支持样式旧版本使用自定义的值或不同的属性从旧的API。 从ICS复制必要的样式 请不要使用这些样式 使用自定义样式 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

那要看什么是你的目标。第一个建议是有道理的,当应用程序的本地风格是对你很重要。 如果你想有全息风格处处那么有没有办法比复制它作为一个风格在所有平台上使用。 看看这个项目: https://github.com/Prototik/HoloEverywhere

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