【问题标题】:How can I change android Toolbar home icon如何更改 android 工具栏主页图标
【发布时间】:2020-01-25 11:31:21
【问题描述】:

我试图更改工具栏图标,例如 Image 01Image 02 和类似的后退图标。

我可以使用更改默认图标颜色

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/whit</item>
    <item name="colorPrimaryDark">@color/whit</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="drawerArrowStyle">@style/IconStyle</item>
</style>

<style name="IconStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@color/name_heading</item>
</style>

我已经试过了:

toolbar=findViewById(R.id.toolBarId);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_right_select);

但现在可以工作了。 有什么办法可以从 styles.xml 文件?

【问题讨论】:

  • 使用工具栏 API。 toolbar.setNavigationIcon(...)
  • “主页图标”是什么意思?你是在活动还是片段中实现它?
  • 请点击此链接,您将在这里得到预期的答案stackoverflow.com/questions/29038861/…

标签: android android-studio icons toolbar titlebar


【解决方案1】:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.ic_arrow_right_select);

【讨论】:

    猜你喜欢
    • 2015-04-21
    • 2016-03-24
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 2016-08-20
    • 2016-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多