When we create a new application in android,it comes with a default action bar.
There is a difference between action bar and toolbar:
Toolbar is more flexible than action bar.Action bar is only a lign at the top of the activity, but you can use toolbar anywhere in your screen.
With the help of Toolbar you can meet your custom requirements.
Steps to create a toolbar in application in android using kotlin:–
Step 1:- Add a Toolbar in layout (XML File).
Step 2:- You need to change your activity theme in Style.Xml like :–
<Style name=”customtoolbartheme” parent=”Theme.Appcompat.light.No actionabar
// Customize your theme
Step 3:- Now apply your theme in your activity manifest.Xml.
Step 4:- Set all constraints for Toolbar.
Step 5:- Add a TextView in the centre of the Toolbar and set its constraints.
Step 6:- Go to Main Activity.kt,and write the given code:-