Action Bar Android Action Bar incl App Compat

Action. Bar Android Action. Bar incl. App. Compat, Menu etc. Support libraries + Action. Bar 1

Android support libraries • You want to make an application for many (including old) devices. • Problem • No access to modern API + UI features • Solution • Use the Android support libraries to build the application • Gives you access to modern API + UI features • Packages • android. support. v 4. * • android. support. v 7. * • Includes Action. Bar + a lot of other features, like the class App. Compat. Activity • Gradle • The Gradle file (build. gradle) provides information on how to compile etc the application • The relevant support libraries must be referenced in the Gradle file • Latest version (rewrite) • Androidx. appcombat. app. App. Combat. Activity Support libraries + Action. Bar 2

Action. Bar, what is? • Action. Bar is shown at the top of the screen. • Also known as App. Bar • Normally contains • Title and/or logo for the application (or Activity) • Nativation buttons • Up (to parent activity) • Close (end the application) • Etc. • Menu. Items: • Each items triggers an action • Example • App. Bar. Example • Tool. Bar • Similar to Action. Bar, but can be placed everywhere on the screen Support libraries + Action. Bar 3

Action. Bar, show it • Style • The style file defines the style of the application. • Go to the file /res/values/styles. xml • Choose an application style with NO actionbar • This means that there will be no ”automatically generated” action bar • We will ”program” another action bar • Layout files • Define the action bar in the XML layout file of each of your activites • Or define the action bar in a separate file, and include this file in all you XML layout files • Example: toolbar_main. xml, activity_main. xml • Java code • In your Activity, on. Create() method • Add the bar to the view • Example: Main. Activity Support libraries + Action. Bar 4

Menu • The Action. Bar often contains a menu • A menu is essentially a number of small buttons … • The menu items are defined in an XML file • Title, icon, position in the menu, etc. • Example: menu_main. xml • The menu is shown by the Activity • Override the method on. Create. Options. Menu() • Load the relevant menu XML file. • Clicks on the menu items are handled by the Activity • Override the method on. Options. Item. Selected(…) • Normally programmed using a switch statement Support libraries + Action. Bar 5

Action. Provider • Action. Provider is an easy / general way to assign features to your App. Bar • Action. Provider handles its own appearence (title, icon, etc) + behavior (what to do when clicked) • Defined in the menu XML file • Example: App. Bar/menu_main. xml • Programmed in the On. Create. Options. Menu(…) method Support libraries + Action. Bar 6

Up button • Sub-activities sometimes have an ”Up button” that leads to the parent activity • The ”Up button” is normally place in the App. Bar • The Android. Manifest. xml defines which activity is the parent activity • Example • App. Bar/Order. Activity. java Support libraries + Action. Bar 7
- Slides: 7