【问题标题】:When to use homeAsUpIndicator in a toolbar?何时在工具栏中使用 homeAsUpIndicator?
【发布时间】:2019-07-15 15:10:35
【问题描述】:

我在Toolbar 中看到了这一点,例如

<androidx.appcompat.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:navigationIcon="?attr/homeAsUpIndicator">

要么我添加app:navigationIcon="?attr/homeAsUpIndicator",要么如果缺少,即

<androidx.appcompat.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary">

显示返回箭头。我想知道,有没有理由添加?attr/homeAsUpIndicator

【问题讨论】:

    标签: android android-layout android-toolbar android-resources android-theme


    【解决方案1】:

    ?attr/homeAsUpIndicator

    指定一个可绘制的对象,用于“home as up”指示器,该指示器用于导航回之前的页面或活动

    也可以通过编程方式添加

    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true)
    

    访问https://developer.android.com/reference/android/R.attr.html#homeAsUpIndicator 了解一下...

    我希望这会有所帮助...

    【讨论】:

    • 我的问题是,要么我在navigationIcon 中定义了它,要么我没有显示返回箭头。那么区别是什么呢?我的意思是如果默认情况下它显示我需要设置app:navigationIcon="?attr/homeAsUpIndicator"吗?
    • 哦,我明白你的意思了....默认情况下,您不需要在工具栏元素中设置app:navigationIcon="?attr/homeAsUpIndicator"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2015-02-07
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    • 2016-04-13
    相关资源
    最近更新 更多