1 / 20

Themes and Menus: The Sudoku Example

Themes and Menus: The Sudoku Example. Content taken from book: “Hello, Android” by Ed Burnette Third Edition. Review of key concepts. Alternate Resources Defining new activities Starting new activities. Alternate Resources. Defining new activity. res/layout/about.xml.

noura
Download Presentation

Themes and Menus: The Sudoku Example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Themes and Menus:The Sudoku Example Content taken from book: “Hello, Android” by Ed Burnette Third Edition

  2. Review of key concepts • Alternate Resources • Defining new activities • Starting new activities

  3. Alternate Resources

  4. Defining new activity • res/layout/about.xml add strings for the title of the About dialog box and the text it contains to res/values/strings.xml

  5. Starting activities • To start an activity in Android, we first need to create an instance of the Intent class.

  6. Activities and the Manifest • Every activity needs to be declared in AndroidManifest.xml <activity android:name=".About" android:label="@string/about_title" > </activity>

  7. Themes • A theme is a collection of styles that override the look and feel of Android widgets • Themes were inspired by Cascading Style Sheets (CSS) used for web pages • They separate the content of a screen and its presentation or style • Android is packaged with several themes that you can reference by name

  8. Custom themes • You can make up your own theme by subclassing existing ones and overriding their default values • Define your own custom theme in res/values/styles.xml

  9. Predefined Themes • Activities should include a theme property • The AndroidManifest.xml should list the activity definition • To use a predefined theme, change the definition of the activity listed in the AndroidManifest.xml to include a theme property

  10. With/Without custom theme

  11. Android Resources • The @android: prefix in front of the style name means this is a reference to a resource defined by Android, not one that is defined in your program.

  12. Menus • Android supports two kinds of menus. • First, there is the menu you get when you press the physical Menu button. • Second, there is a context menu that pops up when you press and hold your finger on the screen (or press and hold the trackball or the D-pad center button).

  13. Menu from “menu key” • res/menu/menu.xml • strings.xml

  14. Modify sudoku.java getMenuInflater( ) returns an instance of MenuInflater that we use to read the menu definition from XML and turns it into a real view. When the user selects any menu item, onOptionsItemSelected( ) will be called.

  15. Program preferences • res/xml/settings.xml

  16. Preferences activity • Prefs.java The addPreferencesFromResource( ) method reads the settings definition from XML and inflates it into views in the current activity.

  17. Add Prefs activity to Manifest • Modify AndroidManifest.xml to include the Prefs activity

  18. New game option • res/values/strings.xml • res/values/arrays.xml

  19. Modify Sudoku class • Sudoku.java

  20. Exiting the game • Modify the Sudoku.java file

More Related