Added simple demos for ActionBar
Change-Id: Ie0dbf0c2bad61f75825e832305205811f49459d1
This commit is contained in:
@@ -652,6 +652,23 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Action Bar Samples -->
|
||||
<activity android:name=".app.ActionBarMechanics"
|
||||
android:label="@string/action_bar_mechanics">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".app.ActionBarUsage" android:label="@string/action_bar_usage"
|
||||
android:theme="@android:style/Theme.WithActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- ************************************* -->
|
||||
<!-- PREFERENCE PACKAGE SAMPLES -->
|
||||
<!-- ************************************* -->
|
||||
|
||||
44
samples/ApiDemos/res/menu/actions.xml
Normal file
44
samples/ApiDemos/res/menu/actions.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2010 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/action_search"
|
||||
android:icon="@android:drawable/ic_menu_search"
|
||||
android:title="@string/action_bar_search"
|
||||
android:showAsAction="ifRoom"
|
||||
android:onClick="onSearch" />
|
||||
<item android:id="@+id/action_add"
|
||||
android:icon="@android:drawable/ic_menu_add"
|
||||
android:title="@string/action_bar_add" />
|
||||
<item android:id="@+id/action_edit"
|
||||
android:icon="@android:drawable/ic_menu_edit"
|
||||
android:showAsAction="always"
|
||||
android:title="@string/action_bar_edit" />
|
||||
<item android:id="@+id/action_share"
|
||||
android:icon="@android:drawable/ic_menu_share"
|
||||
android:title="@string/action_bar_share"
|
||||
android:showAsAction="ifRoom" />
|
||||
<item android:id="@+id/action_zoom"
|
||||
android:icon="@android:drawable/ic_menu_zoom"
|
||||
android:title="@string/action_bar_zoom"
|
||||
android:showAsAction="ifRoom">
|
||||
<menu>
|
||||
<item android:id="@+id/action_save"
|
||||
android:icon="@android:drawable/ic_menu_save"
|
||||
android:title="@string/action_bar_save"
|
||||
android:showAsAction="ifRoom" />
|
||||
</menu>
|
||||
</item>
|
||||
</menu>
|
||||
@@ -530,6 +530,20 @@
|
||||
<string name="speak_button">Speak!</string>
|
||||
<string name="voice_recognition_results">Results:</string>
|
||||
|
||||
<!-- ================================= -->
|
||||
<!-- app/action bar examples strings -->
|
||||
<!-- ================================= -->
|
||||
|
||||
<string name="action_bar_mechanics">App/Action Bar/Action Bar Mechanics</string>
|
||||
<string name="action_bar_usage">App/Action Bar/Action Bar Usage</string>
|
||||
|
||||
<string name="action_bar_search">Search</string>
|
||||
<string name="action_bar_add">Add</string>
|
||||
<string name="action_bar_edit">Edit</string>
|
||||
<string name="action_bar_share">Share</string>
|
||||
<string name="action_bar_zoom">Zoom</string>
|
||||
<string name="action_bar_save">Save</string>
|
||||
|
||||
<!-- ============================ -->
|
||||
<!-- graphics examples strings -->
|
||||
<!-- ============================ -->
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.example.android.apis.app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* This demonstrates the basics of the Action Bar and how it interoperates with the
|
||||
* standard options menu. This demo is for informative purposes only; see ActionBarUsage for
|
||||
* an example of using the Action Bar in a more idiomatic manner.
|
||||
*/
|
||||
public class ActionBarMechanics extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// The Action Bar is a window feature. The feature must be requested
|
||||
// before setting a content view. Normally this is set automatically
|
||||
// by your Activity's theme in your manifest. The provided system
|
||||
// theme Theme.WithActionBar enables this for you. Use it as you would
|
||||
// use Theme.NoTitleBar. You can add an Action Bar to your own themes
|
||||
// by adding the element <item name="android:windowActionBar">true</item>
|
||||
// to your style definition.
|
||||
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Menu items default to never show in the action bar. On most devices this means
|
||||
// they will show in the standard options menu panel when the menu button is pressed.
|
||||
// On xlarge-screen devices a "More" button will appear in the far right of the
|
||||
// Action Bar that will display remaining items in a cascading menu.
|
||||
menu.add("Normal item");
|
||||
|
||||
MenuItem actionItem = menu.add("Action Button");
|
||||
|
||||
// Items that show as actions should favor the "if room" setting, which will
|
||||
// prevent too many buttons from crowding the bar. Extra items will show in the
|
||||
// overflow area.
|
||||
actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
||||
// Items that show as actions are strongly encouraged to use an icon.
|
||||
// These icons are shown without a text description, and therefore should
|
||||
// be sufficiently descriptive on their own.
|
||||
actionItem.setIcon(android.R.drawable.ic_menu_share);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.example.android.apis.app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.android.apis.R;
|
||||
|
||||
/**
|
||||
* This demonstrates idiomatic usage of the Action Bar. The theme Theme.WithActionBar
|
||||
* is specified for this activity in AndroidManifest.xml and a menu resource is used
|
||||
* to populate the menu data itself. If you'd like to see how these things work under
|
||||
* the hood, see ActionBarMechanics.
|
||||
*/
|
||||
public class ActionBarUsage extends Activity {
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.actions, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
// This method is specified as an onClick handler in the menu xml and will
|
||||
// take precedence over the Activity's onOptionsItemSelected method.
|
||||
// See res/menu/actions.xml for more info.
|
||||
public void onSearch(MenuItem item) {
|
||||
Toast.makeText(this, "Searching...", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user