【问题标题】:Navigation Drawer Using Appcompat v7 - Issues with ?android:attr Tag使用 Appcompat v7 的导航抽屉 - ?android:attr 标签的问题
【发布时间】:2013-08-15 09:41:50
【问题描述】:

我在我的项目中使用了操作栏和导航抽屉。使用 appcompat v7 和 v4。

我已经添加了 appcompat v7 WITH 资源。

以下是我直接从Creating a Navigation Drawer找到的android示例应用程序中提取的导航抽屉列表的文本视图

最后三行都导致我的应用程序失败,它构建得很好,但是我强制关闭,我不知道如何解决这个问题。考虑到我添加了 appcompat 及其资源,我不明白为什么找不到这些属性。或者它们对 appcompat 或其他东西无效?

MinSDK 版本为 10,代码失败。 API 10 以上的代码工作正常。

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

【问题讨论】:

  • 你的minSdkVersion是什么?
  • @vikram - 抱歉 minSDK 版本是 10
  • @vikram,谢谢,也许我误解了,但我认为 appcompat 包 v7 及其资源应该可以解决这个问题?
  • 我删除了我的评论,因为我忽略了I have added the appcompat v7 WITH resources。这里的问题是属性activatedBackgroundIndicatortextAppearanceListItemSmalllistPreferredItemHeightSmall 都在 appcompat v7 中定义,但 activatedBackgroundIndicator 不是。您可以通过查看sdk\extras\android\support\v7\appcompat\res\values\attrs.xml 来验证这一点。 activatedBackgroundIndicator 在 API 11 中添加。这就是代码在 minsdk=10 时失败的原因。就像你说的:Above API 10 the code works fine.
  • 顺便说一下,这是activatedBackgroundIndicator使用的drawable:Link。您可以尝试直接使用它(将其放在 res/drawable 中)。我不确定这是否可行。

标签: java android android-actionbar android-support-library navigation-drawer


【解决方案1】:

您可以使用兼容性库中定义的值:它指定除背景之外的所有值,我选择了 listChoiceBackgroundIndicator,尽管您也可以与其他人一起玩。

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

【讨论】:

    【解决方案2】:

    我有同样的问题。据我了解,较旧的 api 没有预定义 textAppearanceListItemSmall、activatedBackgroundIndicator 和 listPreferredItemHeightSmall。因此,如果您需要,您可以指定自己的值或删除此行并依靠您的运气。

    【讨论】:

    • 我认为这就是 appcompat 包及其所有资源的用途??
    • @Reafidy 我认为 appcompat 负责 ActionBar 资源,而不是负责“listItem”背景、外观和最小高度
    • @Reafidy 是的,应该。但在旧的谷歌时尚中,还有很多不足之处。另外......它充满了错误。 Holoeveryehere 库要好得多且可靠得多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    • 2019-01-09
    相关资源
    最近更新 更多