Reputation: 43
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.
Upvotes: 0
Views: 4300
Reputation: 12866
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:
AppBarLayout
, Toolbar
and CoordinatorLayout
.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:
Upvotes: 1