Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

android - Logo are not displayed in Actionbar, using AppCompat

I don't know where I missed something, but I can't set my logo in my actionbar. My AndroidManifest.xml:

<application 
    android:icon="@drawable/application_icon" 
    android:label="@string/icon_name"
    android:logo="@drawable/actionbar_logo"
    android:theme="@style/PolarTheme">

And also I set my logo in my activity tag in the manifest:

<activity 
    android:name=".Main"
    android:theme="@style/PolarThemeLogo"
    android:logo="@drawable/actionbar_logo"
    android:windowSoftInputMode="adjustPan">
</activity>

This is in my themes.xml:

<style 
    name="PolarThemeLogo" parent="Theme.AppCompat.Light.DarkActionBar">  
    <item name="colorPrimary">@color/mainColor500</item>
    <item name="colorPrimaryDark">@color/mainColor700</item>
    <item name="colorAccent">@color/accentColorA200</item>

    <item name="actionBarStyle">@style/MyActionBarLogo</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

My styles.xml:

<style name="MyActionBarLogo" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="background">@color/mainColor500</item>
    <item name="displayOptions">useLogo</item>
</style>

In my Main.java:

public class Main extends ActionBarActivity {

@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);    
    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle("");
    actionBar.setDisplayUseLogoEnabled(true);

Any ideas?

UPDATE - SOLVED

I removed all the android:logo attributes from my AndroidManifest.xml and I modified my MyActionBarLogo style like this:

<style name="MyActionBarLogo" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="background">@color/mainColor500</item>
    <item name="logo">@drawable/actionbar_logo</item>
    <item name="displayOptions">useLogo|showHome</item>
</style>

Now the actionbar is displaying my logo. :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I use the following code to show the logo, hope it would be helpful.

getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.logo);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...