|
1 | | - |
2 | | -This library adds support for the [Action Bar][4] user interface [design pattern][5]. Here are a few of the key classes included in the v7 appcompat library: |
3 | | - |
4 | | - - ActionBar - Provides an implementation of the action bar user interface pattern. For more information on using the Action Bar, see the Action Bar developer guide. |
5 | | - - ActionBarActivity - Adds an application activity class that must be used as a base class for activities that uses the Support Library action bar implementation. |
6 | | - - ShareActionProvider - Adds support for a standardized sharing action (such as email or posting to social applications) that can be included in an action bar. |
7 | | - |
8 | | - |
9 | | -### Target SDK Version |
10 | | -NOTE: Using this support library requires that your app have its Target Android Version (*targetSdkVersion*) set to Lollipop (5.0 - API Level 21) or higher, or you will have *aapt* related compile errors. You can still set the Target Framework which your app is compiled against as low as Android 4.0.3 (API Level 15). |
11 | | - |
12 | | - |
13 | | -Using ActionBar |
14 | | ------- |
15 | | - |
16 | | -```csharp |
17 | | -[Activity (Label = "@string/action_bar_mechanics", Theme = "@style/Theme.AppCompat")] |
18 | | -public class ActionBarMechanics : ActionBarActivity |
19 | | -{ |
20 | | - protected override void OnCreate (Bundle bundle) |
21 | | - { |
22 | | - base.OnCreate (bundle); |
23 | | - |
24 | | - // The Action Bar is a window feature. The feature must be requested |
25 | | - // before setting a content view. Normally this is set automatically |
26 | | - // by your Activity's theme in your manifest. The provided system |
27 | | - // theme Theme.WithActionBar enables this for you. Use it as you would |
28 | | - // use Theme.NoTitleBar. You can add an Action Bar to your own themes |
29 | | - // by adding the element <item name="android:windowActionBar">true</item> |
30 | | - // to your style definition. |
31 | | - SupportRequestWindowFeature(WindowCompat.FeatureActionBar); |
32 | | - } |
33 | | - |
34 | | - public override bool OnCreateOptionsMenu (Android.Views.IMenu menu) |
35 | | - { |
36 | | - // Menu items default to never show in the action bar. On most devices this means |
37 | | - // they will show in the standard options menu panel when the menu button is pressed. |
38 | | - // On xlarge-screen devices a "More" button will appear in the far right of the |
39 | | - // Action Bar that will display remaining items in a cascading menu. |
40 | | -
|
41 | | - menu.Add(new Java.Lang.String ("Normal item")); |
42 | | - |
43 | | - var actionItem = menu.Add(new Java.Lang.String ("Action Button")); |
44 | | - |
45 | | - // Items that show as actions should favor the "if room" setting, which will |
46 | | - // prevent too many buttons from crowding the bar. Extra items will show in the |
47 | | - // overflow area. |
48 | | - MenuItemCompat.SetShowAsAction(actionItem, MenuItemCompat.ShowAsActionIfRoom); |
49 | | - |
50 | | - // Items that show as actions are strongly encouraged to use an icon. |
51 | | - // These icons are shown without a text description, and therefore should |
52 | | - // be sufficiently descriptive on their own. |
53 | | - actionItem.SetIcon(Android.Resource.Drawable.IcMenuShare); |
54 | | - return true; |
55 | | - } |
56 | | - |
57 | | - public override bool OnOptionsItemSelected (Android.Views.IMenuItem item) |
58 | | - { |
59 | | - Android.Widget.Toast.MakeText (this, |
60 | | - "Selected Item: " + |
61 | | - item.TitleFormatted, |
62 | | - Android.Widget.ToastLength.Short).Show(); |
63 | | - |
64 | | - return true; |
65 | | - } |
66 | | -} |
67 | | -``` |
68 | | - |
69 | | - |
70 | | -*Portions of this page are modifications based on [work][3] created and [shared by the Android Open Source Project][1] and used according to terms described in the [Creative Commons 2.5 Attribution License][2].* |
71 | | - |
72 | | -[1]: http://code.google.com/policies.html |
73 | | -[2]: http://creativecommons.org/licenses/by/2.5/ |
74 | | -[3]: http://developer.android.com/tools/support-library/features.html |
75 | | -[4]: http://developer.android.com/guide/topics/ui/actionbar.html |
76 | | -[5]: http://developer.android.com/design/patterns/actionbar.html |
77 | | - |
| 1 | + |
| 2 | +This library adds support for the [Action Bar][4] user interface [design pattern][5]. Here are a few of the key classes included in the v7 appcompat library: |
| 3 | + |
| 4 | + - ActionBar - Provides an implementation of the action bar user interface pattern. For more information on using the Action Bar, see the Action Bar developer guide. |
| 5 | + - ActionBarActivity - Adds an application activity class that must be used as a base class for activities that uses the Support Library action bar implementation. |
| 6 | + - ShareActionProvider - Adds support for a standardized sharing action (such as email or posting to social applications) that can be included in an action bar. |
| 7 | + |
| 8 | + |
| 9 | +### Target SDK Version |
| 10 | +NOTE: Using this support library requires that your app have its Target Android Version (*targetSdkVersion*) set to Lollipop (5.0 - API Level 21) or higher, or you will have *aapt* related compile errors. You can still set the Target Framework which your app is compiled against as low as Android 4.0.3 (API Level 15). |
| 11 | + |
| 12 | + |
| 13 | +Using ActionBar |
| 14 | +------ |
| 15 | + |
| 16 | +```csharp |
| 17 | +[Activity (Label = "@string/action_bar_mechanics", Theme = "@style/Theme.AppCompat")] |
| 18 | +public class ActionBarMechanics : ActionBarActivity |
| 19 | +{ |
| 20 | + protected override void OnCreate (Bundle bundle) |
| 21 | + { |
| 22 | + base.OnCreate (bundle); |
| 23 | + |
| 24 | + // The Action Bar is a window feature. The feature must be requested |
| 25 | + // before setting a content view. Normally this is set automatically |
| 26 | + // by your Activity's theme in your manifest. The provided system |
| 27 | + // theme Theme.WithActionBar enables this for you. Use it as you would |
| 28 | + // use Theme.NoTitleBar. You can add an Action Bar to your own themes |
| 29 | + // by adding the element <item name="android:windowActionBar">true</item> |
| 30 | + // to your style definition. |
| 31 | + SupportRequestWindowFeature(WindowCompat.FeatureActionBar); |
| 32 | + } |
| 33 | + |
| 34 | + public override bool OnCreateOptionsMenu (Android.Views.IMenu menu) |
| 35 | + { |
| 36 | + // Menu items default to never show in the action bar. On most devices this means |
| 37 | + // they will show in the standard options menu panel when the menu button is pressed. |
| 38 | + // On xlarge-screen devices a "More" button will appear in the far right of the |
| 39 | + // Action Bar that will display remaining items in a cascading menu. |
| 40 | +
|
| 41 | + menu.Add(new Java.Lang.String ("Normal item")); |
| 42 | + |
| 43 | + var actionItem = menu.Add(new Java.Lang.String ("Action Button")); |
| 44 | + |
| 45 | + // Items that show as actions should favor the "if room" setting, which will |
| 46 | + // prevent too many buttons from crowding the bar. Extra items will show in the |
| 47 | + // overflow area. |
| 48 | + MenuItemCompat.SetShowAsAction(actionItem, MenuItemCompat.ShowAsActionIfRoom); |
| 49 | + |
| 50 | + // Items that show as actions are strongly encouraged to use an icon. |
| 51 | + // These icons are shown without a text description, and therefore should |
| 52 | + // be sufficiently descriptive on their own. |
| 53 | + actionItem.SetIcon(Android.Resource.Drawable.IcMenuShare); |
| 54 | + return true; |
| 55 | + } |
| 56 | + |
| 57 | + public override bool OnOptionsItemSelected (Android.Views.IMenuItem item) |
| 58 | + { |
| 59 | + Android.Widget.Toast.MakeText (this, |
| 60 | + "Selected Item: " + |
| 61 | + item.TitleFormatted, |
| 62 | + Android.Widget.ToastLength.Short).Show(); |
| 63 | + |
| 64 | + return true; |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | +*Portions of this page are modifications based on [work][3] created and [shared by the Android Open Source Project][1] and used according to terms described in the [Creative Commons 2.5 Attribution License][2].* |
| 71 | + |
| 72 | +[1]: http://code.google.com/policies.html |
| 73 | +[2]: http://creativecommons.org/licenses/by/2.5/ |
| 74 | +[3]: http://developer.android.com/tools/support-library/features.html |
| 75 | +[4]: http://developer.android.com/guide/topics/ui/actionbar.html |
| 76 | +[5]: http://developer.android.com/design/patterns/actionbar.html |
| 77 | + |
0 commit comments