【问题标题】:How do I apply the HoloEverywhere android theme when using ActionBarSherlock?使用 ActionBarSherlock 时如何应用 HoloEverywhere android 主题?
【发布时间】:2012-07-27 06:46:50
【问题描述】:

我正在构建一个应该在 android 2.3 上运行的应用程序,并且我添加了 ActionBarSherlock 和 HoloEverywhere 库。

为了使用 ActionBarSherlock 我必须像这样使用 Theme.Sherlock :

<application
    ...
    android:theme="@style/Theme.Sherlock"
    ...  >

没关系。

我的主要活动非常简单:只是一个有 5 行的 ListView(我不使用 ListAcivity)。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/menuListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

因为是android 2.3,我还是有橙黑主题的(当然除了ActionBar)。现在我想通过像这样修改我的清单来添加 HoloEverywhere 主题:

<application
    ...
    android:theme="@style/Theme.HoloEverywhereDark.Sherlock"
    ...  >

但这并没有改变任何东西......我错过了什么?

【问题讨论】:

  • 我需要像以前版本中的 ICS 这样的微调器。但我尝试在任何地方导入 ActionBarSherlock 和 Holoevery。但是在 eclipse 中导入后会抛出很多错误。另外请告诉我们不能在没有 ActionBarSherlock 的情况下在任何地方使用 holoeevery 吗?
  • 哪些错误?是的,你可以在没有 actionbarsherlock 的情况下使用 Holoeverywhere
  • 喜欢资源未找到错误。我所做的步骤是从现有代码导入 is->File->New Project->Android Project。
  • 检查 R.java 文件是否正确生成,有时不是。此外,您应该在 HoloEverywhere 项目的属性中将 ActionBarSherlock 项目设置为库。

标签: android android-actionbar actionbarsherlock android-theme android-holo-everywhere


【解决方案1】:

为了默认为我进入 HoloEverywhere 库的 styles.xml 文件中的每个 ListView 启用 Holo 主题,然后我通过添加以下行来修改“ListViewStyle”元素:

<item name="android:listSelector">@drawable/list_selector_holo_dark</item>

【讨论】:

    【解决方案2】:

    我对 ListView 的选择器也有同样的问题。我虽然默认情况下 HoloEveruwhere 会应用全息选择器(蓝色)(我已经尝试过 Theme.HoloEverywhereLight 和 Theme.HoloEverywhereLight),但它没有。也许我错过了什么。

    我最终手动设置了选择器:

    listView.setSelector(R.drawable.list_selector_holo_light);
    

    您可以在库中使用多个可绘制资源(例如 list_selector_holo_light)。

    【讨论】:

    • 这确实有效,但我必须为每个 ListView 都这样做。
    【解决方案3】:

    一个可移植且正确的解决方案是从 ListViewStyle 继承并覆盖该属性,使其在您的 styles.xml 中。

    如果您在服务器上远程部署了 HoloEverywhere 官方库(例如 Maven 存储库),则您不能依赖它来维护 styles.xml 中的更改(您正在根据自己的需要对其进行修改)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-10
      • 2012-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多