I am using a custom toolbar layout with a TextView in ToolBar
But when I run it
It hint that
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fish.sevenseconds/com.goldfish.sevenseconds.activities.Addmem}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.Toolbar.setTitle(java.lang.CharSequence)' on a null object reference
this is my Activity code
toolbar=(Toolbar) findViewById(R.id.square_toolbar);
toolbar.setTitle("");
This is my xml
<android.support.v7.widget.Toolbar
android:id="#+id/admem_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/khaki"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#color/silver"
android:textSize="20sp" />
</android.support.v7.widget.Toolbar>
Cheeck the below code change the id to match the xml for findviewbyid for toolbar
toolbar=(Toolbar) findViewById(R.id.admem_toolbar);
toolbar.setTitle("");
XML
<android.support.v7.widget.Toolbar
android:id="#+id/admem_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/khaki"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#color/silver"
android:textSize="20sp" />
</android.support.v7.widget.Toolbar>
Related
I'm trying to set actionbar on my Android Studio project. While debugging, Android Studio doesn't show any error but when I run my app, it stops at this line. Please suggest me the perfect way of working with toolbar on Android Studio.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Edit:
The aforementioned code is from my Activity class file. And here is the extract from my XML file
<androidx.appcompat.widget.Toolbar
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="#+id/toolbar"
android:background="#color/colorPrimaryDark"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
<FrameLayout
android:id="#+id/fragment_container"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Here is a quick way to use android toolbar> Use toolbar in XML file :
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/blue"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
>
<ImageView
android:id="#+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_arrow_back_24_white"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:contentDescription="#string/back_button" />
<TextView
android:id="#+id/tag1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/create_a_push_notification"
android:textColor="#color/white"
android:layout_toEndOf="#+id/backButton"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:layout_marginStart="10dp"
android:textSize="20sp"
android:textStyle="bold"/>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
Here is the toolbar you can access any component via id. The toolbar will look like this:
Trying to set the ActionBar title in middle instead of the default left aligned position. To do so, based on other answers this is what I've done:
Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbarDownloads);
setSupportActionBar(myToolbar);
if(getSupportActionBar()!=null)
{
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.actionbar_layout);
}
actionbar_layout.xml
<?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="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Downloads"
android:layout_centerInParent="true"
android:textColor="#000000"
android:id="#+id/mytext"
android:textSize="18sp" />
</RelativeLayout>
However, this does not produce the intended result (ie this renders the text however still is left aligned), what's wrong with this approach and how to fix this?
try this use custom Toolbar
<android.support.v7.widget.Toolbar
android:id="#+id/ar_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="exitUntilCollapsed"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Center"
android:orientation="vertical">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
now in java file
private Toolbar toolbar;
toolbar = (Toolbar) findViewById(R.id.ar_toolbar);
TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
mTitle.setText("Nilesh Rathod");
setSupportActionBar(toolbar);
Simple approach use android:layout_gravity="center" on your TextView and hide default title using below code after that initialize your TextView and set value
Inside your activity:
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbar_title = (TextView) findViewById(R.id.toolbar_title);
toolbar_title.setText("My Custom center title");
Custom toolbar XML Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Toolbar Title" />
</android.support.v7.widget.Toolbar>
You need to use Toolbar in your xml file and you can use TextView inside Toolbar. You can add custom view into Toolbar. Once you done with xml file then you can define Toolbar into Activity class.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="58dp"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:titleTextColor="#ffffff">
<TextView
android:id="#+id/mytext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Downloads"
android:textColor="#000000"
android:textSize="18sp" />
</android.support.v7.widget.Toolbar>
//Rest of your code
</LinearLayout>
In Activity class you can define as
Toolbar toolbar;
toolbar = (Toolbar) findViewById(R.id.ar_toolbar);
toolbar.setTitle("");
You don't need a Toolbar for this. Just use a theme like Theme.AppCompat.Light.DarkActionBar with ActionBar in your activity and use the following code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.actionbar_layout);
}
//your code
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:minHeight="?attr/actionBarSize"
app:contentInsetStart="0dp">
<TextView
android:id="#+id/back_txt"
style="#android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="Back" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Downloads"
android:layout_gravity="center|center_horizontal|center_vertical"
android:layout_marginTop="20dp"
android:layout_centerInParent="true"
android:textColor="#000000"
android:id="#+id/mytext"
android:textSize="18sp" />
<TextView
android:id="#+id/filter_btn"
style="#style/Base.TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical|center_horizontal"
android:layout_margin="10dp"
android:drawablePadding="5dp"
android:gravity="center"
android:text="Back"
android:textColor="#android:color/black" />
</android.support.v7.widget.Toolbar>
</LinearLayout>
I am working with a simple application on android where at the moment i net to create a toolbar so i created a custom toolbar like this:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:layout_gravity="center"
android:id="#+id/toolbar_title"
/>
</android.support.v7.widget.Toolbar>
then i included this custom layout on my activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.afcosta.inesctec.pt.android.FamilyLibrary">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_menu_camera"
app:backgroundTint="#f1c40f"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="37dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="33dp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/gallery"
android:layout_width="0dp"
android:layout_height="562dp"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="97dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
layout="#layout/custom_toolbar"
android:id="#+id/toolbar"
tools:layout_constraintTop_creator="1"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/textView3"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Familias"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toTopOf="#+id/gallery"
android:layout_marginStart="8dp"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="15dp"
app:layout_constraintLeft_toLeftOf="parent"
android:textSize="24dp"/>
when i try to setText on my activity for the TextView, i fails and i get this error: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.support.v7.widget.Toolbar.findViewById(int)' on a null object reference
here is my code on the activity:
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);;
setSupportActionBar(myToolbar);
TextView toolbarText = (TextView) myToolbar.findViewById(R.id.toolbar_title);
toolbarText.setText("Famílias");
Any tip?
Thank you very much!
If I'm not mistaken, you don't need to call findViewById() on your toolbar, you should just be able to use this: findViewById(R.id.toolbar_title)
Your code should end up looking like this:
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
TextView toolbarText = (TextView) findViewById(R.id.toolbar_title);
toolbarText.setText("Famílias");
You are giving two different id to toolbar layout
android:id="#+id/my_toolbar"
and in main layout while including you are giving
<include
layout="#layout/custom_toolbar"
android:id="#+id/toolbar" />
make these ids same
On the beginning - i tried all solutions.
Here is the error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.justfashion.ActivityMainWallet.onCreate(ActivityMainWallet.java:211)`
ActivityMainWallet.java:210-212 lines:
TextView navigationTotalCreditTextView = (TextView)mDrawerLay.findViewById(R.id.nav_drawer_total_credits);
navigationTotalCreditTextView.setText("Total Credits: " + PreferenceConnector.readInteger(aiContext,
PreferenceConnector.WALLETPOINTS,""));
XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<TextView
android:id="#+id/nav_drawer_wallet_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:textColor="#color/md_white_1000"
android:textSize="#dimen/twentyfive" />
<TextView
android:id="#+id/nav_drawer_total_credits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#color/md_white_1000"
android:textSize="#dimen/twentyfive" />
<TextView
android:id="#+id/nav_drawer_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:textColor="#color/md_white_1000"
android:textSize="#dimen/twentyfive" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:id="#+id/content_frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:layout_below="#+id/toolbar_app_bar_layout">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</RelativeLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar_app_bar_layout" />
<android.support.design.widget.AppBarLayout
android:id="#+id/toolbar_app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include android:id="#+id/toolbar"
layout="#layout/toolbar" />
<android.support.design.widget.TabLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
app:tabMode="scrollable"
app:paddingStart="16dp"
app:tabPaddingStart="16dp"
app:tabPaddingEnd="16dp"
app:tabMinWidth="96dp"
app:tabGravity="center" />
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="#color/md_white_1000"
app:headerLayout="#layout/nav_drawer_header"
app:menu="#menu/menu_drawer"
app:itemTextAppearance="#style/TextAppearance.AppCompat.Menu"
android:clipToPadding="false">
<!--<FrameLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="bottom"-->
<!--android:background="#color/md_white_1000"-->
<!--android:elevation="4dp"-->
<!--android:layout_marginBottom="-96dp">-->
<!--<Button android:id="#+id/navigation_button_footer"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:text=""-->
<!--android:textSize="13sp"-->
<!--android:textColor="#color/md_grey_800"-->
<!--android:lines="3"-->
<!--android:gravity="center"-->
<!--style="#style/Widget.AppCompat.ActionButton"-->
<!--android:paddingTop="20dp"-->
<!--android:paddingLeft="20dp"-->
<!--android:paddingRight="20dp"-->
<!--android:paddingBottom="20dp"/>-->
<!--</FrameLayout>-->
</android.support.design.widget.NavigationView>
<RelativeLayout
android:id="#+id/lay_connection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/actmain_margintop"
android:background="#3c3c3c"
android:visibility="gone" >
<TextView
android:id="#+id/text_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/error_no_internet"
android:textColor="#color/md_white_1000"
android:textSize="#dimen/twentyfive" />
<RelativeLayout
android:id="#+id/lay_dialog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" >
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/progressBar1"
android:layout_centerHorizontal="true"
android:text="#string/error_no_internet"
android:textColor="#color/md_white_1000"
android:textSize="#dimen/twentyfive" />
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
I tried everything. Is it a problem with PreferenceConnector? Here is PreferenceConnector.WALLETPOINTS,"")) in PreferenceConnection.java:
public static final String WALLETPOINTS = "walletpoints";
Help guys please! I tried every solution, but noone has got this error with PreferanceConnector.
#EDIT
Solved, but now i'm getting this error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.Toolbar.setTitle(java.lang.CharSequence)' on a null object reference at com.justfashion.ActivityMainWallet.onCreate(ActivityMainWallet.java:251)
The problem is that you are searching for TextView in wrong View.
You did this :
TextView navigationTotalCreditTextView = (TextView)mDrawerLay.findViewById(R.id.nav_drawer_total_credits);
But the text view is in mDrawerLayout. see below and also your xml.
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
mDrawerLay = (NavigationView)findViewById(R.id.navigation_view);
to fix the problem do this :
TextView navigationTotalCreditTextView = (TextView)mDrawerLayout.findViewById(R.id.nav_drawer_total_credits);
Try this;
TextView navigationTotalCreditTextView = (TextView)findViewById(R.id.nav_drawer_total_credits);
navigationTotalCreditTextView.setText("Total Credits: " + PreferenceConnector.readInteger(aiContext,
PreferenceConnector.WALLETPOINTS,""));
I had this problem too. It take my time a lot. After working a day on it and helpless searching I found out that I have two layout from a layout for two different API level and I must change TextView id for both of them finally I solved it I hope it be helpful for others that are in a bad trouble like me
I am trying to change the action bar properties of my activities but I am getting an error "Error inflating class toolbar".
Here is the code snippet :
import android.support.v7.widget.Toolbar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vendor_details);
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Details");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Here is the Android Manifest code for that activity :
<activity
android:name=".VendorDetails"
android:label="VendorDetails"
android:theme="#style/AppTheme.NoActionBar"/>
And the layout code for the toolbar is :
<Toolbar
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary">
</Toolbar>
Does anyone know how to solve it?
I am stuck on it since yesterday now. Thanks in advance.
Here is the full xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.sachinparashar.omitravendorassistance.Verify"
tools:showIn="#layout/activity_verify">
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Enter the Code sent"
android:id="#+id/verifyText"
android:padding="5dp"
android:layout_marginTop="32dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/userCode"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
android:hint="Enter Code"
android:gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Verify"
android:id="#+id/verify"
android:layout_marginTop="100dp"
android:textStyle="bold|italic"
android:textSize="20dp"
android:layout_below="#+id/userCode"
android:layout_centerHorizontal="true"
android:onClick="onVerify" />
<Button
android:layout_width="110dp"
android:layout_height="wrap_content"
android:text="Resend"
android:id="#+id/resend"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/verify"
android:layout_centerHorizontal="true"
android:layout_marginTop="37dp"
android:onClick="onResend"
android:visibility="invisible" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="700dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/timer"
android:layout_below="#+id/userCode"
android:layout_centerHorizontal="true"
android:layout_marginTop="31dp"
android:textSize="25dp"
android:gravity="center_horizontal" />
You need to use Toolbar as below in xml.
<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">
</android.support.v7.widget.Toolbar>