Reputation: 93
I am currently trying to change the style of my action bar to accomplish the following:
In order to do so, this is what I have tried:
Manifest
file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shoppinglist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppThemeWithoutActionBarTitle">
<activity
android:name="com.example.shoppinglist.MainActivity"
android:label="@string/app_name"
android:logo="@drawable/mylogo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And in styles.xml
:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<style name="ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#ffffff</item>
</style>
<style name="ActionBarWithoutTitle" parent="@style/ActionBar">
<item name="android:displayOptions">useLogo</item>
</style>
<style name="AppThemeWithoutActionBarTitle" parent="AppTheme">
<item name="android:actionBarStyle">@style/ActionBarWithoutTitle</item>
</style>
</resources>
However, when I tried this, everything worked except for replacing the app logo: instead of the new logo @drawable/mylogo
, no logo appears at all. How can I fix this?
Upvotes: 0
Views: 88
Reputation: 31
You are close to the right answer. All you need is to modify one element in your styles.xml
file to the following:
<style name="ActionBarWithoutTitle" parent="@style/ActionBar">
<item name="android:displayOptions">showHome|useLogo</item>
</style>
The addition of showHome|
will allow for the logo you need to be present.
Upvotes: 2
Reputation: 7371
You need to set in your Activity
whether you want to use the launcher icon or the logo icon. So add this line to your Activity
in onCreate
:
setDisplayUseLogoEnabled(true);
Also your approach can be done programatically as well:
getActionBar().setTitle("");
getActionBar().setLogo(R.drawable.my_logo);
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.my_background_drawable));
This would of course be a good solution, if you wanted to add different styles to different Activities
, but would be a bit cumbersome, if you have more Activities
and wanted the same style all over.
Upvotes: 0