android里面meum的写法

– 搬运自2016年的旧博客

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 //MENU 
 @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
	inflater.inflate(R.menu.preview\_line\_chart, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  int id = item.getItemId();
  if (id == R.id.action\_reset) {
    generateDefaultData();
    chart.setLineChartData(data);
    previewChart.setLineChartData(previewData);
    previewX(true);
    return true;
  }
  if (id == R.id.action\_preview\_both) {
    previewXY();
    previewChart.setZoomType(ZoomType.HORIZONTAL\_AND\_VERTICAL);
    return true;
  }
  if (id == R.id.action\_preview\_horizontal) {
    previewX(true); return true;
  }
  if (id == R.id.action\_preview\_vertical) {
    previewY(); return true;
  }
  if (id == R.id.action\_change_color) {
    int color = ChartUtils.pickColor();
    while (color == previewChart.getPreviewColor()) {
      color = ChartUtils.pickColor();
    }
    previewChart.setPreviewColor(color); return true;
  }
  return super.onOptionsItemSelected(item);
}