The different versions of Android introduced by Actionbar have differences and are summarized below
One, in the support.v7 package
Introduce layouts using the parameters in the oncreateoptionsmenu method: Inflate
Import Android.support.v7.app.actionbaractivity;public class Combolinecolumnchartactivity extends ActionBarActivity { //menu @Override public void Oncreateoptionsmenu (Menu menu, Menuinflater inflater) { Inflater.inflate (R.menu.combo_line_column_chart, menu); } @Override Public Boolean onoptionsitemselected (MenuItem item) { int id = item.getitemid (); if (id = = r.id.action_reset) { reset (); Generatedata (); return true; } if (id = = r.id.action_add_line) { addlinetodata (); return true; } ...... return super.onoptionsitemselected (item);} }
Layout file:
In the Menu folder
R . Menu . Combo_line_column_chart
<menu xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:app= "http://schemas.android.com/ Apk/res-auto " xmlns:tools=" Http://schemas.android.com/tools " tools:context=" Lecho.lib.hellocharts.samples.ComboLineColumnChartActivity "> <item android:id=" @+id/action_ Reset " android:title=" reset chart " app:showasaction=" never "/> <item android:id=" @+id/ Action_add_line " android:title=" add line " app:showasaction=" never "/> <item android:id = "@+id/action_toggle_lines" android:title= "Toggle lines/scattered" app:showasaction= "Never"/></ Menu>
Reference Hellocharts-android/combo_line_column_chart.xml at Master Lecho/hellocharts-android
Https://github.com/lecho/hellocharts-android/blob/master/hellocharts-samples/res/menu/combo_line_column_chart.xml
:
2. In the activity
Introduction of layout to use the Getmenuinflate method under activity
public class Articlelistactivity extends Activity { @Override public boolean oncreateoptionsmenu (Menu menu) { C2/>getmenuinflater (). Inflate (r.menu.list, menu); return true; } @Override Public Boolean onoptionsitemselected (MenuItem item) { int id = item.getitemid (); if (id = = r.id.action_settings) { return true; } return super.onoptionsitemselected (item);} }
Layout code:
In the Menu folder
R.menu.list
<menu xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http://schemas.android.com /tools " tools:context=". MyActivity "> <item android:id=" @+id/action_settings " android:title=" @string/action_settings " android:orderincategory= "android:showasaction=" never "/></menu>
Reference:
Hellocharts-android/combo_line_column_chart.xml at Master Lecho/hellocharts-android
Https://github.com/lecho/hellocharts-android/blob/master/hellocharts-samples/res/menu/combo_line_column_chart.xml
:
Android system comes with Actionbar summary