Action bar custom view

25,538

Best way is to use XML styles:

<style name="Theme.Main" parent="android:Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/Widget.ActionBar</item>
</style>

<style name="Widget.ActionBar" parent="android:Widget.Holo.Light.ActionBar">
    <item name="android:displayOptions">showHome|useLogo|showCustom</item>
    <item name="android:customNavigationLayout">@layout/custom</item>
</style>

Then simply set this theme as either the application theme or activity them in AndroidManifest.xml

Share:
25,538
FHan
Author by

FHan

Updated on May 29, 2020

Comments

  • FHan
    FHan almost 4 years

    I want to declare a custom view, BUT I also want the home logo with up icon to appear on the left with its default functionality. How can I achieve to use both?

  • Joe Trellick
    Joe Trellick about 12 years
    You can also do the same in code without any theme changes: getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUST‌​OM|ActionBar.DISPLAY‌​_USE_LOGO|ActionBar.‌​DISPLAY_SHOW_HOME);