在Android中构建菜单

时间:2011-12-19 20:02:33

标签: android menu

我正在编写一个需要这样菜单的Android应用程序:

enter image description here

请注意,此活动有一个背景和4个菜单项,其中每个菜单项有两个部分:应与左右对齐的底部文本和右边对齐的文本。你能告诉我如何实现它吗?我应该为每个菜单项使用LinearLayout吗?

1 个答案:

答案 0 :(得分:0)

这是我制作的示例代码。所有这些都是xml中的按钮

public class MenuActivity extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
}


@Override
// My menu inflater
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(this).inflate(R.menu.menu, menu);

return (super.onCreateOptionsMenu(menu));
}

// code for the actions that it will do.
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.test2:
    test2();
    return true;
case R.id.test1:
    test1();
    return true;
default:
    return super.onOptionsItemSelected(item);
}
}

 public void test1() {
// TODO Auto-generated method stub
Toast test = Toast.makeText(this, "This is a test", Toast.LENGTH_LONG);
test.show();
 }

 public void test2() {
// TODO Auto-generated method stub
Toast test = Toast.makeText(this, "This is a test", Toast.LENGTH_LONG);
test.show();
  //Add how ever many you want. 
 }
}