簡體   English   中英

如何使用導航抽屜添加自定義操作欄?

[英]How to add custom action bar with navigation drawer?

我嘗試使用自定義操作欄作為:

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並放入可繪制文件夾)而不是應用程序圖標。 您可以通過為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>

對我來說工作:

getActionBar().setCustomView(R.layout.xyz); getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);

actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM