sama sama - 28 days ago 6
Android Question

How can I create my custom ActionBar?

I'm new in Android & I want to create a custom actionbar for my application like the image below:
enter image description here

how can I create this?in the circle I want to insert my image and instead of "welcome", I want to write my user's name.
what can I do for this?
appreciating any help.

Edit:
my layout's theme is AppTheme, and it has an action bar I don't want that,How can I delete it to Insert custom actionbar?

Answer

After searching around my problem,I found my response: I create an xml file with linearlayout and whithin its tags I added the code I inserted below.

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:layout_gravity="right">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:minHeight="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="@color/blue"
        >


    </android.support.v7.widget.Toolbar>
    <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/img1"
                    android:src="@drawable/books2"
                    android:background="@drawable/icon"
                    android:layout_alignParentTop="true"
                    android:layout_alignRight="@+id/toolbar"

        android:layout_gravity="bottom|right" />


</FrameLayout>

For Imageview's shape,I use this code:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<gradient
    android:angle="90"
    android:startColor="@color/blue"
    android:centerColor="@color/blue"
    android:endColor="@color/blue"
    android:type="linear"/>

<corners
    android:radius="70dp"
    />
<size
    android:height="40dp"
    android:width="40dp"
    />

and I include this in my activity's layout XML file.

<include layout="@layout/titlebar"/>

Hope it will useful for you.

Comments