相关疑难解决方法(0)

工具栏导航图标从未设置

我正在尝试新的工具栏组件,并在导航图标上遇到一些问题.我想为后台导航实现自定义图标:

在我的清单中,我将父母设置为我的活动:

<activity android:name=".CardsActivity" android:parentActivityName=".MainActivity">
    <!-- Parent activity meta-data to support API level 7+ -->
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".MainActivity" />
</activity>
Run Code Online (Sandbox Code Playgroud)

我声明工具栏是这样的:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.lollitest.MainActivity" >

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_awesome_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:layout_marginBottom="10dp"
        android:background="?attr/colorPrimary" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/my_awesome_toolbar"
        android:text="@string/hello_world" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

然后在我的活动中我配置工具栏如下:

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
toolbar.setNavigationIcon(R.drawable.ic_good);
toolbar.setTitle("Title");
toolbar.setSubtitle("Sub");
toolbar.setLogo(R.drawable.ic_launcher);
setSupportActionBar(toolbar);
Run Code Online (Sandbox Code Playgroud)

哪个给我: 带后退按钮的工具栏

后面的图标不是我设置的图标setNavigationIcon()!无论我为方法提供什么样的绘图,导航图标始终是后退箭头.

我试图删除清单中的父关联,但唯一的效果是(显然)阻止按钮返回.

相反,如果我想要默认的后退箭头图标而不打电话setNavigationIcon()我根本没有任何图标.

处理工具栏中的导航图标(自定义和默认)的正确方法是什么?

NOte:我在Android 4.4上运行我的测试

android android-appcompat android-actionbar-compat material-design android-toolbar

64
推荐指数
4
解决办法
12万
查看次数