Skip to content

Instantly share code, notes, and snippets.

@cyrilmottier
Last active January 30, 2023 00:04
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save cyrilmottier/7085463 to your computer and use it in GitHub Desktop.
Save cyrilmottier/7085463 to your computer and use it in GitHub Desktop.
Android example of how to add a custom logo to the ActionBar and ensure the best possible matching starting Window.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyrilmottier.android.anapp">
<!-- ... -->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/config_app_name"
android:theme="@style/Theme.AnApp" >
<activity
android:name="com.cyrilmottier.android.anapp.LauncherActivity"
android:theme="@style/Theme.AnApp.Logo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- ... -->
</application>
</manifest>
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="Widget.ActionBar" parent="...">
<!-- ... -->
</style>
<style name="Widget.ActionBar.Logo">
<item name="android:logo">@drawable/app_text_logo</item>
<item name="android:displayOptions">useLogo|showHome</item>
</style>
</resources>
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="Theme.AnApp" parent="...">
<item name="android:actionBarStyle">@style/Widget.ActionBar</item>
<!-- ... -->
</style>
<style name="Theme.AnApp.Logo">
<item name="android:actionBarStyle">@style/Widget.ActionBar.Logo</item>
<!-- ... -->
</style>
</resources>
@morristech
Copy link

thanks for the share!

@robertoestivill
Copy link

Works flawlessly. Thanks for sharing!

@sm-tester
Copy link

android:logo not found

@RoelRoel
Copy link

Does not work for me on Android 5.0

@cingh-jasdeep
Copy link

cingh-jasdeep commented Sep 25, 2018

Waheguru ji
thanks for the answer

from android course on udacity

https://github.com/udacity/ud851-Sunshine/tree/student/S12.02-Exercise-Styles

One can use
logo
instead of
android:logo

and
displayOptions
instead of
android:displayOptions

to avoid target sdk error

so code can be something like

<style name="Widget.ActionBar.Logo">
        <item name="logo">@drawable/app_text_logo</item>
        <item name="displayOptions">useLogo|showHome</item>
</style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment