0

Here an example

here is the pic please can any one suggest me how to change the icon colour and title to center to the action bar ...

Orbi
  • 61
  • 8

2 Answers2

0

Try this:
change pading if you want.

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="@dimen/abc_action_bar_default_height_material">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1"
        >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/ic_edit"

            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="ABC"
            android:gravity="center"
            android:layout_weight="1"
            android:textColor="@android:color/white"

            />
        <ImageView
            android:layout_width="wrap_content"
            android:paddingRight="10dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/ic_edit"/>
    </LinearLayout>
</android.support.v7.widget.Toolbar>

enter image description here

Govinda P
  • 3,261
  • 5
  • 22
  • 43
  • what error? your xml layout not display correctly ? – Govinda P Mar 21 '16 at 11:00
  • thank you @Govinda , then how to add a edit text n button in the layout so that user can input its details and submit to the next page .. please suggest me and thank you for the help – Abhishek khatua Mar 22 '16 at 02:04
  • back = (Toolbar) findViewById(R.id.back); setSupportActionBar(back); back.setNavigationIcon(R.drawable.ic_navigate_before_white_24dp); back.invalidate() here is the code i have tried still not working so can u suggest me where is my fault.. – Abhishek khatua Mar 22 '16 at 05:22
0

Try like this.

Create new layout custom_toolbar.xml in your project.

Add below code in above file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <ImageView
        android:id="@+id/imgLeft"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="10dp"
        android:src="@drawable/ic_events" />

    <ImageView
        android:id="@+id/imgRight"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_centerHorizontal="true"
        android:layout_marginRight="10dp"
        android:src="@drawable/ic_action" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="Test"
        android:textColor="@android:color/white"
        android:textSize="25sp" />


</RelativeLayout>

And then add that layout to your toolbar xml file.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/ColorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

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

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

Hope this will help you.

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58