android - 4.1 工具栏中缺少向上箭头

标签 android android-actionbar android-toolbar android-4.1-jelly-bean

我已经设置了自定义工具栏。但出于某种原因,在 4.1 上,向上箭头 Assets 不会显示。触摸区域仍然存在并且可以正常工作,但 Assets 不会显示。

下面是创建工具栏的代码。 (工具栏设置在我的基本 Activity 的其他地方)

public ActionBar(AppCompatActivity activity) {
    Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
    toolbar.findViewById(R.id.header_layout).setVisibility(View.GONE);

    actionBar = activity.getSupportActionBar();
    savedDisplayOptions = actionBar.getDisplayOptions();
    savedTitle = actionBar.getTitle();
    actionBar.setDisplayShowCustomEnabled(false);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeAsUpIndicator(R.drawable.up_button);
    actionBar.setDisplayShowHomeEnabled(false);
}

这是按钮 xml。如您所见,我修复了 4.1 中操作栏的错误(我尝试删除它但无济于事)

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:left="@dimen/double_spacing"
    android:right="@dimen/double_spacing">
    <shape>
        <size android:height="@dimen/standard_icon_size" android:width="@dimen/standard_icon_size"/>
        <!-- DO NOT REMOVE, this fixes a bug on 4.1 where the background defaults to black -->
        <solid android:color="@color/transparent"/>
    </shape>

</item>
<item
    android:left="@dimen/double_spacing">
    <bitmap android:src="@drawable/ic_up_arrow" android:gravity="left"/>
</item>

最后这就是我的工具栏的样子。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/action_bar_height"
    android:elevation="@dimen/half_spacing"
    app:theme="@style/ToolbarTheme"
    android:background="@color/white"
    tools:ignore="UnusedAttribute">

   <com.mypackage.core.view.TextView
       android:id="@+id/standard_toolbar_title"
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
       android:ellipsize="end"
       android:maxLines="1"
       style="@style/H5.Blue" />

    <com.mypackage.util.graphics.ActionBarView
        android:id="@+id/max_header_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"/>

</android.support.v7.widget.Toolbar>

我刚刚发现的有趣的事情。如果我从 up_button xml 中的位图中删除重力属性,则会出现箭头,但会大大拉伸(stretch)。如果我随后移除透明项目,它会再次消失。

最佳答案

看起来这是老黑客本身。删除它并直接指向 Assets 后,一切都很好。

关于android - 4.1 工具栏中缺少向上箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31591457/

相关文章:

android - 如何删除 Android 操作栏的底部边框?

android.support.v7.widget.Toolbar 图标对齐问题

android - 删除 fragment 中的 ActionBar

javascript - Cordova 对话框插件 : insert HTML tags in notification. 警报消息

android - 如果我选择大图像,OnActivityResult 会崩溃

android - Android 中的 Lucene

Android:调整操作栏溢出菜单下拉的位置

android - Android Honeycomb 3.0 中的文本高亮显示

android - 如何在我正在 Robotium 中测试的类中调用方法

android - 折叠工具栏标题消失