【问题标题】:How to change back button in material design?如何更改材料设计中的后退按钮?
【发布时间】:2014-12-23 11:59:50
【问题描述】:

过去我们在样式中使用这个属性来替换操作栏上的后退图标:

<item name="android:homeAsUpIndicator">@drawable/up_indicator</item>

但工具栏的类似方法不起作用:

 <style name="Toolbar" parent="@style/Widget.AppCompat.Toolbar">
        <item name="android:windowNoTitle">true</item>
        <item name="title">@null</item>
        <item name="homeAsUpIndicator">@null</item>
 </style>

您对此有解决方案吗,或者您可以分享具有这种样式的源代码链接吗?我自己没找到。我们将不胜感激所有帮助

【问题讨论】:

  • 看看这个示例项目:github.com/greenhalolabs/lollipopsamples希望对你有帮助
  • 它不包含自定义后退 btn,它只是带有 navdrawer 的新工具栏的一个示例(实际上它很糟糕 - nad 抽屉应该按照指南与工具栏重叠)。无论如何,感谢您的帮助!

标签: android material-design android-support-library android-toolbar android-appcompat


【解决方案1】:

要使用样式更改Toolbar 中的后退图标,您可以在您的应用主题中使用类似的内容:

   <style name="AppTheme" parent="Theme.AppCompat.Light">
       <item name="homeAsUpIndicator">@drawable/up_indicator</item>
    </style>

您可以通过编程方式使用:

  • Toolbar:
Toolbar toolbar = findViewById(R.id.xxx);
toolbar.setNavigationIcon(R.drawable.xxxx4);
setSupportActionBar(toolbar);
  • 带有ActionBar,您可以使用:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.xxx);

【讨论】:

  • 正如我在帖子中提到的,这种方法不起作用。我已经尝试过 aith 并且没有“android:”前缀。工具栏用作操作栏 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar);
  • 在您的问题中,您使用的是@style/Widget.AppCompat.Toolbar,而我使用的是样式 Theme.AppCompat.Light 来应用于 Activity。
  • 抱歉,复制粘贴错字。我也使用 Theme.AppCompat.Light" 问题仍然存在
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-09
  • 2014-10-12
  • 2016-06-28
  • 2015-01-04
  • 2016-09-20
  • 2019-04-10
  • 2015-09-07
相关资源
最近更新 更多