menu
Posted zqxLonely
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了menu相关的知识,希望对你有一定的参考价值。
menu_main.xml
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:title="添加" android:id="@+id/add"/> <item android:title="删除" android:id="@+id/delete"/> </menu>
MainActivity.java
package com.pingyijinren.helloworld.activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import com.pingyijinren.helloworld.R; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main,menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()){ case R.id.add: Log.d("MainActivity","add"); break; case R.id.delete: Log.d("MainActivity","delete"); break; } return true; } }
以上是关于menu的主要内容,如果未能解决你的问题,请参考以下文章
Operator '||' cannot be applied to operands of type 'bool?' and 'bool?'(代码片段
Operator '||' cannot be applied to operands of type 'bool?' and 'bool?'(代码片段