Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to implement Toolbar

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 275
    Comment on it

    Using Toolbar in place of ActionBar:-

    Nowadays ActionBar is getting replaced by toolbar, so it is good to use or get handy with new feature of Android i.e "ToolBar" , Here is the way to use toolbar in your Android Activity.

    Step 1:- set the app theme in style.xml

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" >
            <item name="android:windowTranslucentStatus">true</item>
        </style>
    

    Step 2:- Create an xml file toolbar.xml

    <?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="@android:color/holo_blue_dark"
        android:elevation="4dp"
        android:padding="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark" >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal">
    
            <ImageView
                android:id="@+id/profile_picture"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/user_pic" />
    
            <ImageView
                android:id="@+id/setting"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
    
                android:background="@drawable/settings" />
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>
    

    Step 3:- Include the above designed toolbar into XML file of your main Activity

    <?xml version="1.0" encoding="utf-8"?>
    
    <android.support.v4.widget.DrawerLayout
    
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/DrawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="7dp">
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <include
                android:id="@+id/headertoolbar"
                layout="@layout/toolbar">
            </include>
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Flowers" 
                android:layout_gravity="center"
                android:gravity="center_horizontal"
                android:padding="10dp"
                android:textSize="20dp"
                android:background="@android:color/holo_orange_light"/>
    
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/flowers"/>
    
        </LinearLayout>
    </android.support.v4.widget.DrawerLayout>
    

    Step:4 Set toolbar in your mail activity in onCreate method

    Toolbar toolbar;   // Declaring the Toolbar Object
     toolbar = (Toolbar) findViewById(R.id.headertoolbar);  // Assinging  toolbar object        
      setSupportActionBar(toolbar);  //setting the the Action bar to our toolbar
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: