0

This is my menu-main.xml.

The picture below the code shows where I want to put the logo on my app.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.akam.billettogram.MainActivity">**strong text**
    <item
        android:id="@+id/logo"
        app:showAsAction="always"
        android:title=""
        android:layout_gravity="center"
        android:icon="@drawable/logo"/>
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>
</menu>

Position that I want to put my logo in.

Evin1_
  • 12,292
  • 9
  • 45
  • 47
1987akam
  • 43
  • 1
  • 7
  • 1
    Don't. Android Apps don't have logos in the center of the action bar, the action bar should be used to give context of the screen the user is on. Example: photo gallery should have the text "Photos" or "Photo Gallery" in the action bar, not a logo. – CodyEngel Feb 03 '16 at 01:09
  • ok thanks for helping – 1987akam Feb 03 '16 at 01:12
  • 1
    You would have to define a new toolbar item with a textbox inside (with centered gravity), and set the theme of your Activity as NoActionBar. I will put an example in the answers in a sec. – Evin1_ Feb 03 '16 at 02:36
  • 1
    Possible duplicate of [ActionBar - custom view with centered ImageView, Action Items on sides](http://stackoverflow.com/questions/16026818/actionbar-custom-view-with-centered-imageview-action-items-on-sides) – Dhaval Parmar Feb 03 '16 at 03:47

1 Answers1

1

So, the easiest way for you to do it is creating a new Empty Activity in Android Studio, make sure it is Empty and not Blank!

This template will build all the code needed:

  • It will create your Activity.java.
  • Create the layout with an AppBarLayout, Toolbar and CoordinatorLayout.
  • It will create the needed styles in your res/values.
  • It will set the Activity with the proper style in the Manifest (NoActionBar).

So... you will just have to add your icon and maybe a TextView inside the automatically created Toolbar (in the layout.xml) as seen in the following snippet:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay">

    <LinearLayout
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:src="@android:drawable/btn_star_big_off"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:text="Hello world"
            android:textColor="@android:color/white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

</android.support.v7.widget.Toolbar>

Below is an image with the result:

enter image description here

Evin1_
  • 12,292
  • 9
  • 45
  • 47