Implementing Toolbar(ActionBar) in SUSI Android

SUSI is an artificial intelligence for interactive chat bots. The SUSI Android app ( has a toolbar, that allows different user preferences right up in the menu option. These include functionalities such as search, login, logout and rating the app. The material design toolbar provides a clean and efficient way to do these functions. We will see how we implemented this in the SUSI Android app.

To implement ActionBar in the Android app we will start with adding the dependency below to the gradle file.

compile `` 

For more information regarding setting up ActionBar in your own project please refer to this link.

Now we will add the Toolbar in our XML file as shown below.

< xmlns:app=""












      app:srcCompat="@drawable/ic_susi_white" />


On Adding the above code we can see the preview of the Toolbar which appears like this.


Now we will see how to implement the menu options. In the menu_main.xml we can add options to be shown in the toolbar.

<menu xmlns:android=""










      app:showAsAction="always" />




      android:title="Search Down"






      android:title="Search Up"







      app:showAsAction="never" />





      app:showAsAction="never" />





      app:showAsAction="never" />

We can define different items in the ActionBar as shown above. Also, we have the option by which we can set the visibility of the items. If the visibility of the item is false, then it will be shown in the overflow menu like this.

Now we will see how we can add functionalities to the options present in the menu ActionBar. To add the listeners to the options we have to override the function onCreateOptionsMenu and there we can add the logic for different options as shown below.


  public boolean onCreateOptionsMenu(final Menu menu) { = menu;

      getMenuInflater().inflate(, menu);

      if(PrefManager.getBoolean(Constant.ANONYMOUS_LOGGED_IN, false)) {



      } else if(!(PrefManager.getBoolean(Constant.ANONYMOUS_LOGGED_IN, false))) {




      searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(;

      final EditText editText = (EditText)searchView.findViewById(;

      searchView.setOnSearchClickListener(new View.OnClickListener() {

[email protected]

          public void onClick(View view) {





              isEnabled = false;




For diving more into the code, we can refer to the GitHub repo of Susi Android (


Published by


Android Developer at Fossasia