我尝试使用自定义操作栏作为:
bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
bar.setCustomView(R.layout.xyz);
但是抽屉导航变得不可见。
最佳答案
我遇到了同样的问题,但我找到了解决该问题的方法。您需要设置:
getActionBar().setCustomView(R.layout.xyz);
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
然后,它会显示抽屉导航+图标。
如果你不希望图标可见,你可以放一个透明图像(只需制作透明图像 transparent.png
并放在 drawable 文件夹中)而不是应用程序图标。您可以通过为 Action Bar (styles.xml
) 定义新样式来做到这一点:
<style name="Theme.MyAppTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/Theme.MyAppTheme.ActionBar</item>
</style>
<style name="Theme.MyAppTheme.ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:icon">@drawable/transparent</item>
</style>
关于android - 如何使用抽屉导航添加自定义操作栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21039586/