Last active
January 30, 2023 00:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Works flawlessly. Thanks for sharing!
android:logo not found
Does not work for me on Android 5.0
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
thanks for the share!