如何使用 API 8 上的 AppCompat 在 Android ActionBar 上删除文本和徽标或添加溢出? [英] How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8?

查看:19
本文介绍了如何使用 API 8 上的 AppCompat 在 Android ActionBar 上删除文本和徽标或添加溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经研究到死,只是找不到答案.

Have researched this to death and just cannot find the answer.

我有一个使用 AppCompat 的 ActionBar.我最多支持 API v7(API v8 可以).ActionBar 从 API v11 完美运行.API

I have an ActionBar using AppCompat. I am supporting up to API v7 (API v8 would do). ActionBar works perfectly from API v11. API < v11 has the problem of removing an icon (and thus a feature) from the ActionBar without supplying an Overflow. The big picture is that I have an App Logo, an App Title, and 3 Icons all squidging into the same ActionBar on a low end phone. Trying to make some room!

我会对 2 个解决方案中的一个感到满意.要么:

I would be happy with 1 of 2 solutions. Either:

  1. 一种获取溢出的方法,以便可以从下拉列表中检索功能.
  2. (首选)从 ActionBar 中移除图标和文本的方法

以下是我当前用于 API 11+ 的 XML:

Below is my current XML for API 11+:

<resources>

    <!--
        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from res/values/styles.xml on API 11+ devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/LiteActionBarStyle</item>
        <item name="actionBarStyle">@style/LiteActionBarStyle</item>
    </style>

    <style name="LiteActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:displayOptions"></item>
    </style>

</resources>

特别是:

<item name="android:displayOptions"></item>

这是 API v11 之前不可用的属性.

This iss the attribute that is unavailable before API v11.

这是我目前所在的位置:

This is where I am so far:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="actionBarStyle">@style/LiteActionBarStyle</item>
    </style>

    <style name="LiteActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"></style>

</resources>

v11 之前的 API 有哪些替代方案?

What is the alternative for APIs prior to v11?

使用透明度建议更新样式:

Updated Style with transparency suggestion:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="actionBarStyle">@style/LiteActionBarStyle</item>
    </style>

    <style name="LiteActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:icon">@android:color/transparent</item>
    </style>

</resources>

推荐答案

解决了!

使用 API 时

v11,你必须删除Style中属性的android:"元素.例如:

When working with API < v11, you have to remove the "android:" element of the attribute in Style. For example:

<style name="LiteActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="displayOptions"></item>
    </style>

这就是它在带有 API >= v11 的样式中的外观

This is how it should look in Styles with API >= v11

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/LiteActionBarStyle</item>
        <item name="actionBarStyle">@style/LiteActionBarStyle</item>
    </style>

    <style name="LiteActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:displayOptions"></item>
    </style>

此外,当我在带有 API < 的设备上应用此图标时,我遗漏了一些图标.v11.我不得不将图标更改为始终显示:

Also, I was missing some Icons when I applied this on device with API < v11. I had to change the Icons to Always display:

<item
        android:id="@+id/actionInvertShake"
        MyApp:showAsAction="always"
        android:contentDescription="@string/shakeChangeContentDescription"
        android:icon="@drawable/shake"
        android:title="@string/shakeOption"/>

注意命名空间是MyApp"而不是android"

Note that the Namespace is "MyApp" rather than "android"

这会从 ActionBar 中删除 App 的标题和图标,并从右到左显示所有图标.

This removes the Title and Icon of App from ActionBar and displays all icons from Right to Left.

这篇关于如何使用 API 8 上的 AppCompat 在 Android ActionBar 上删除文本和徽标或添加溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆