1 / 7

Lecture 8

Lecture 8. the Preference Menu. We add some strings to the strings.xml file in the values folder. These will be used in the Settings... menu. < string name = "settings_label" > Settings... </ string > < string name = "settings_title" > Sudoku settings </ string >

josh
Download Presentation

Lecture 8

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. Lecture 8 the Preference Menu

  2. We add some strings to the strings.xml file in the values folder. These will be used in the Settings... menu. <stringname="settings_label">Settings...</string> <stringname="settings_title">Sudoku settings</string> <stringname="settings_shortcut">s</string> <stringname="music_title">Music</string> <stringname="music_summary">Play background music</string> <stringname="hints_title">Hints</string> <stringname="hints_summary">Show hints during play</string>

  3. menu.xml <?xmlversion="1.0"encoding="utf-8"?> <menuxmlns:android="http://schemas.android.com/apk/res/android"> <itemandroid:id="@+id/settings" android:title="@string/settings_label" android:alphabeticShortcut="@string/settings_shortcut"/> </menu> right-click the menu folder, choose New->File name the new file menu.xmland insert the following xml code...

  4. Creating a new sub-Folder in the Resources (res) Folder <?xmlversion="1.0"encoding="utf-8"?> <menuxmlns:android="http://schemas.android.com/apk/res/android"> <itemandroid:id="@+id/settings" android:title="@string/settings_label" android:alphabeticShortcut="@string/settings_shortcut"/> </menu>

  5. Modifying the onCreateOptionsMenu( ) Method In the Sudoku.java class, there is boolean method called onCreateOptionsMenu( ) as shown here. we modify this method in the following manner... getMenuInflater( ) returns an instance of MenuInflater that we use to read the menu definition from XML and turns it into a real view. @Override publicboolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.sudoku, menu); returntrue; } @Override publicboolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); returntrue; }

  6. Registering the settings Activity in the Manifest

  7. Example Run: Preference Menu

More Related