編輯:Android開發實例
- view plaincopy to clipboardprint?
- <?xml version="1.0" encoding="utf-8"?>
- <menu
- xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:id="@+id/menu_add"
- android:title="Add"
- android:icon="@android:drawable/ic_menu_add"
- />
- <item android:id="@+id/menu_wallaper"
- android:title="Wallpaper"
- android:icon="@android:drawable/ic_menu_gallery"
- />
- <item android:id="@+id/menu_search"
- android:title="Search"
- android:icon="@android:drawable/ic_search_category_default"
- />
- <item android:id="@+id/menu_setting"
- android:title="Settings"
- android:icon="@android:drawable/ic_menu_preferences"
- />
- </menu>
- <?xml version="1.0" encoding="utf-8"?>
- <menu
- xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:id="@+id/menu_add"
- android:title="Add"
- android:icon="@android:drawable/ic_menu_add"
- />
- <item android:id="@+id/menu_wallaper"
- android:title="Wallpaper"
- android:icon="@android:drawable/ic_menu_gallery"
- />
- <item android:id="@+id/menu_search"
- android:title="Search"
- android:icon="@android:drawable/ic_search_category_default"
- />
- <item android:id="@+id/menu_setting"
- android:title="Settings"
- android:icon="@android:drawable/ic_menu_preferences"
- />
- </menu>
三、主類MenuInflaterDemo.java 的編碼,這裡寫的代碼很少哦,我這裡只寫了第四個菜單(Settings )的響應事件.全部代碼如下:
四、運行代碼之,點擊模擬器上的menu 按鈕將會出現上述效果圖! Ok~今天就到這裡,祝大家周末愉快!!!!
- view plaincopy to clipboardprint?
- package com.android.tutor;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.MenuItem;
- public class MenuInflaterDemo extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.options_menu, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.menu_add:
- break;
- case R.id.menu_wallaper:
- break;
- case R.id.menu_search:
- break;
- case R.id.menu_setting:
- showSettings();
- break;
- }
- return super.onOptionsItemSelected(item);
- }
- private void showSettings(){
- final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
- settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
- Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
- startActivity(settings);
- }
- }
- package com.android.tutor;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.MenuItem;
- public class MenuInflaterDemo extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.options_menu, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.menu_add:
- break;
- case R.id.menu_wallaper:
- break;
- case R.id.menu_search:
- break;
- case R.id.menu_setting:
- showSettings();
- break;
- }
- return super.onOptionsItemSelected(item);
- }
- private void showSettings(){
- final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
- settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
- Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
- startActivity(settings);
- }
- }
本文出自 “Android_Tutor” 博客,請務必保留此出處http://weizhulin.blog.51cto.com/1556324/311446
最近在寫一個應用,想把設置頁面和應用頁面放在一起,這樣就能實現用戶可以實時看到自己的設置對UI的影響,從而更方便的設置用戶喜歡的界面。想了一段時間,發現用slid
Android UI缺省的標題欄由android:label 定義,顯示在屏幕
JSON代表JavaScript對象符號。它是一個獨立的數據交換格式,是XML的最佳替代品。本章介紹了如何解析JSON文件,並從中提取所需的信息。Android提供了四個
可以顯示在的Android任務,通過加載進度條的進展。進度條有兩種形狀。加載欄和加載微調(spinner)。在本章中,我們將討論微調(spinner)。Spinner 用