1

n the action bar only appears the title and the app icon is hide. What can I do to show the app icon?

I try many things for example the logo and a lot of others codes but anything work.

MyActivity:

package com.example.myapp;

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.MenuItem;

public class MyActivity extends ActionBarActivity {
    private InterstitialAd interstitial;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);        
    }
}

My Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp" >
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/icona"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.Light.DarkActionBar"  >

        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>

        <activity
            android:name=".MyActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Main2Activity"
            android:label="@string/title_activity_main2"
            android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
        </activity>
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>

</manifest>

My layout activity:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@drawable/fons"
    tools:context=".Myctivity">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_margin="25sp"
        android:orientation="horizontal" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="hello world" />

    </LinearLayout>

</RelativeLayout>

And in my main.xml I haven't any item

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
ais3
  • 11
  • 3
  • Try [this](http://stackoverflow.com/questions/27612424/v7-21-actionbaractivity-not-showing-the-app-main-icon-on-the-left/27625961#27625961) – Vintesh Jun 01 '15 at 05:56

5 Answers5

1

Try to do this after onCreate

getActionbar().setHomeButtonEnabled(true);
getActionbar().setDisplayHomeAsUpEnabled(true);
Boldijar Paul
  • 5,405
  • 9
  • 46
  • 94
1

See the answer here - it's not present in V21 as the style guidelines have changed: No App Icon on ActionBar

Community
  • 1
  • 1
Binnie
  • 51
  • 2
0

You can access the home image view directly with

ImageView imgHome = (ImageView)findViewById(android.R.id.home);

You can then try changing background color, padding or checking visibility etc... to help debug

imgHome.setBackgroundColor(Color.parseColor("#ff0000"));

imgHome.setPadding(30, 0, 30, 0);

if (imgHome.getVisibility() == View.VISIBLE) {
   // visible
} else {
   // not visible
}

Good luck.

  • That code is for api 11. Is there any code to api 9? Also When I start the apk doesn't work. A message says: Unfortunately, your app have been closed – ais3 Dec 14 '14 at 19:09
0

You can set the icon app in your ActionBar from your manifest file. See these lines

<application
    android:allowBackup="true"
    android:icon="@drawable/icona"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light.DarkActionBar"  >

So @drawable/icona means that you have an icon which called "icona" in your drawable folders.

res/drawable-ldpi, res/drawable-mdpi ...

So add your icona.png file in folders above.

p.s I don't know what you mean when you said "the icon is an arrow" but i can imagine that you mean the up icon button. So this is not your app icon, your app icon located to the folders above. You can see more about the arrow in android Api here.

I hope to help you!

Eleftherios
  • 186
  • 1
  • 13
  • yes I have the icon (icona.png) in the drawables folders. The drawables work well because the background image work well and in the android studio when Iwrite :android:icon="@drawable/icona" in the manifest at the left of the screen appers the icon. – ais3 Dec 16 '14 at 15:32
0

Try this

mActionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);

Vikram
  • 1,072
  • 2
  • 20
  • 33