大多数android程序的右上角都会设置一个菜单按钮比如微信的界面右上角的加号。
这个需要在layout同级目录下新建文件夹命名为menu,再右击新建的menu新建xml文件:
JSL3m7a2h4bX94bf/triGzNJQ3D126LgmRc/EHkpTNZq+fO/7mueVsNpvNZh9M9TBpJHajnGtKlfLNE/EH0vKZQ8c1rwEgODyvrrtDdNnAmgAIBMLdqLi7/OdvTqaFR1Rc0sKj//jvk3YyUi8ZXtsff/TL+KNfhtf2zdJQiJdI38ePHJKtRVq69BYjH7KmnDj+1tv+Nw/1RL6Xrp87LudSUgqRE8fhLsAaz64J0IC1GBEIhKvhxFjd312coO7y2fBXNnMZuYtkloaiVhOD17QZhsaDqR6d0MBdQH686S4ffPCB24eAQCC8Hk64y68Pt6zdfyCK4ur6g18fbrGZi3oJ13VheE26cHef67pgloZix11Iq4x5LrgLsAXcBVGhCCC8EW7/0Go4HHpGuu2zIVEU23jtgBULihurm99dDl26LknXz8kWcmbJsCOJuou88ciUIMFdgBq4C6JCEQgEOsd+BPUN3KWUcMhdfsU1jURjv+Ka7Gcp7hnpvO7yltyIIo/VJRJj6C5vve0/MiXI/UpLy2h3KRdu3+ogEDUQrl9ZQaUJwF1KCMxNB5wG9TIA1ujPkXsmMTkvuH60oDjgLqVE9boLqFfgLgBYY99dbif/DH2pUeAupQTcBTgN3AUAa8zcRb8xOCFCX2qUenWXpu7Unakfrne3VnQvcBfgNHAXAKyx7y40XD/m2qJj9Om8KGWz2dTtZ1vS3vz0k47R3RUpMz76xLFjgLuUEnAX4DRwFwCs0Z8jF2a2L8xsGya2+Kgzd5GWpL356Sfq7bsrkiSJz/odvFpXD/3JPenhbufYjx3TcJeaDLgLcBq4CwDW6M+Rf++ctoO+KOIuW+LeVvIpu70/uZfNZj3rLuMPJc0XAneprXjD19QCgJOU0V0M7yk7bmQ8WyOD2uX169f0tbW7rEydvPS7tn/vnA6fbVuZOmnHXVaSz7aYC3PH6NN5cW8+6d0zpQrdhWubSWZSY2S1jY2Z1t7U9t6LrUyKz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CXUsJD7pJ/HUe4izknBybj4U/Ji9lckC3BcHxi4JT9orR9RuuZyfUMfTt6969jq38dv5eZXM8MJ3fJRjN30VSyAJSI2S+qIHdp9PMxQbOlsB9qBed3YVtHTNwl95GcS3Ga3EY6fiUYF+yN1VX94SMJyeOjdOl/2W0BqOGoXndJp9OiUWxububNW/l1HL3lLo0dv5+Y/P1JUlvpTKXRf6p/crK/o8h6eXzt2fjaM32yqfuZsbvydlN3MX9UIe9TD7ReJhvx+APwmXWXsL8lYbb7+KfsUzndx8P53aXAH1UZ3aUKGUlIaBz1wV1Ki+p1l4HzXxi6S/9A/vOzlCZWO3jNXYLh+KXcIbGvlcMOhUkbjB009XLkzk+ROz/pk325uku3F+ouBTz1QLbj8QfQ1OKz+kWx/SP6p3Iq6y71RLlml6kDAoFAA6LYqF538TW1rN27pxGX1bU1Oxmpl3T2DUfW9yPr+5192qdUTPqM2PpIO72BkpKprfSNq6pylFbZyLIkxOIJiykT0nFek4wOZ9Mfj35KhlxKg6YFH7Ui8wOQJCEWN7zpVJpVGv2n+ifjcodRPKzslGmYsXPGsm8vJv9yMfkXfTJ2e8HuYvepB/b5Tzz+AApwF/XoEMWG9U/oWBRrRr26y0hCKtesvnUA3KWU+H9UsfNEl/us/wAAAABJRU5ErkJggg==" alt="" />
xml文件代码:
class="brush:css;gutter:true;"><menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/id_action_add"
app:showAsAction="always"
android:title="add"
android:icon="@mipmap/ic_launcher"
android:orderInCategory="1"
/>
<item
android:id="@+id/id_action_delete"
app:showAsAction="always"
android:title="jian"
android:icon="@mipmap/ic_launcher"
android:orderInCategory="1"
/>
</menu>
上面的两个item代表代表的是你菜单栏上面有几个按钮。android:icon中可以自定义菜单项的图片
接着是MainActivity种要重写一下代码:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
//新建的xml文件
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
//根据不同的id点击不同按钮控制activity需要做的事件
switch (item.getItemId())
{
case R.id. id_action_add:
//事件
break;
case R.id. id_action_delete:
//事件
break;
}
return true;
}
备忘。。。。。