Sudhanshu Jain
Sudhanshu Jain

Reputation: 29

Toolbar title not showing

I am new to Android and creating a custom toolbar I have set a textview and some images in my toolbar but it is not visible.`Below is the code

 and image of my emulator

I have used this link for tutorial http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/

<android.support.design.widget.CoordinatorLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="130dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="85dp"
                android:background="?attr/colorPrimary">
                <!--app:layout_scrollFlags="scroll|enterAlways"-->
                <!--app:popupTheme="@style/ThemeOverlay.AppCompat.Light">-->

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/ToolBarTitle"
                    android:layout_gravity="bottom"
                    android:layout_marginBottom="35dp"
                    android:id="@+id/toolbar_title"
                    android:textColor="#FFFFFF"
                    android:textSize="17.3sp"
                    android:layout_marginLeft="127dp"

                    />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="6dp"
                    android:layout_gravity="bottom"
                    android:layout_marginBottom="50dp"
                    android:background="@drawable/icn_dropdown" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginBottom="45dp"
                    android:layout_marginLeft="110dp"
                    android:background="@drawable/icn_options"/>
            </android.support.v7.widget.Toolbar>

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#f5f5f5"
                app:theme="@style/TabTheme"
                app:tabIndicatorColor="@color/colorPrimary"
                app:tabTextColor="@color/tab_text"/>
        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"  />


    </android.support.design.widget.CoordinatorLayout>

Upvotes: 1

Views: 2808

Answers (3)

Shivanshu Verma
Shivanshu Verma

Reputation: 601

enter image description here

i do the same thing and it work fine for me:
try like this:

  <?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:layout_marginBottom="30dp"
    android:background="@color/ColorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.Light">

    <ImageView
        android:id="@+id/back"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@drawable/arr" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_gravity="center"

        android:gravity="center"
android:textSize="20sp"
        android:text="New Post"
        android:textColor="#fff"
        />

    <TextView
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_gravity="right"
        android:layout_marginRight="10dp"
        android:gravity="right"
        android:textSize="15sp"
        android:text="Post"
        android:textColor="#fff"
        />


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

Upvotes: 1

inkedTechie
inkedTechie

Reputation: 684

try Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); getSupportActionBar(toolbar); toolbar.setTitle("required title"); in onCreate and if you need images too, then try changing
android:label="" android:icon="" in activity tag of AndroidManifest.xml file

Upvotes: 0

Muhammad Younas
Muhammad Younas

Reputation: 1603

Use below code to set Title of custom title bar

Toolbar mToolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Tittle");

Upvotes: 1

Related Questions