In AppCompat, ToolBar is implemented in the 7.widget.Toolbar class.
#Menu icon android studio android
However, Android has updated the AppCompat support libraries so the ToolBar can be used on lower Android OS devices as well. ToolBar works well with apps targeted to API 21 and above. ToolBar's appearance can be more easily customized than the ActionBar. It's a ViewGroup that can be placed anywhere in your layout. ToolBar was introduced in Android Lollipop, API 21 release and is the spiritual successor of the ActionBar. When you want to add primary actions to the ActionBar, you add the items to the activity context menu and if properly specified, they will automatically appear at the top right as icons in the ActionBar.Īn activity populates the ActionBar from within the onCreateOptionsMenu() method: public class MainActivity extends AppCompatActivity Īnd then you can handle all the action buttons in this single method.
#Menu icon android studio plus
You can read more about this on the material design guidelines which state: "The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer." Adding Action Items setDisplayShowHomeEnabled ( true ) supportActionBar. setDisplayUseLogoEnabled ( true ) supportActionBar. setDisplayShowHomeEnabled ( true ) getSupportActionBar (). Although the icon can be added back with: getSupportActionBar (). In the new Android 5.0 material design guidelines, the style guidelines have changed to discourage the use of the icon in the ActionBar. See the Extended ActionBar Guide for more details. You can also change many other properties of the ActionBar not covered here. setTitle ( "My new title" ) // set the top title hide () // or even hide the actionbar supportActionBar. setTitle ( "My new title" ) // set the top title String title = actionBar. In any Java activity, you can also call getSupportActionBar() to retrieve a reference to the ActionBar and modify or access any properties of the ActionBar at runtime: ActionBar actionBar = getSupportActionBar () // or getActionBar() getSupportActionBar (). Ĭhange the android:label or android:icon to modify the ActionBar title or icon for a given activity or for the application as a whole. In the example below, the activity "FirstActivity" will have an ActionBar with the string value of the resource identified by If the value of that resource is "Foo," the string displayed in the ActionBar for this activity will be "Foo." Note that the application node can supply a android:label that acts as the default for activities and components with no other specified label. The ActionBar title displayed at the top of the screen is governed by the AndroidManifest.xml file within the activity nodes. The ActionBar by default now has just the title for the current activity. ActionBar BasicsĮvery application unless otherwise specified has an ActionBar by default. Since most of the examples below depend on this support library, make sure to include the AppCompat library. In 2013, Google announced a support library that provides much better compatibility for older versions and support for tabbed interfaces. Important to note is that prior to 3.0, there was no ActionBar. Consistent navigation (including navigation drawer).An application or activity-specific title.An "upward" navigation to logical parent.The ActionBar, now known as the App Bar, is a consistent navigation element that is standard throughout modern Android applications.