Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Is it possible to replace the actionbar with a toolbar?


Asked by Alisson Calderon on Nov 28, 2021 FAQ



I'm trying to replace the ActionBar of my app with a Toolbar but I can't because I can't use setSupportActionBar (). It says "setSupportActionBar () is undefined for the type MainActivity" even if MainActivity extends ActionBarActivity.
Keeping this in consideration,
To replace an app's default action bar with a Toolbar: Create a new custom theme and modify the app's properties so that it uses this new theme. Disable the windowActionBar attribute in the custom theme and enable the windowNoTitle attribute. Define a layout for the Toolbar.
Accordingly, The toolbar bar (formerly known as action bar) is represented as of Android 5.0 via the Toolbar view group. It can be freely positioined into your layout file. It can display the activity title, icon, actions which can be triggered, additional views and other interactive items.
In addition,
Position the toolbar at the top of the activity's layout, since you are using it as an app bar. In the activity's onCreate() method, call the activity's setSupportActionBar() method, and pass the activity's toolbar. This method sets the toolbar as the app bar for the activity.
And,
Your app now has a basic action bar. By default, the action bar contains just the name of the app and an overflow menu. The options menu initially contains just the Settings item. You can add more actions to the action bar and the overflow menu, as described in Adding and Handling Actions.