[android]代码库
1.Main.java
//添加menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.gatt_services, menu);
}
//点击menu菜单后摇执行的功能
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_connect:
mBluetoothLeService.connect(mDeviceAddress);
return true;
case R.id.menu_disconnect:
mBluetoothLeService.disconnect();
return true;
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
2.menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_refresh"
android:checkable="false"
android:orderInCategory="1"
android:title="refresh" />
<item android:id="@+id/menu_connect"
android:title="connect"
android:orderInCategory="100" />
<item android:id="@+id/menu_disconnect"
android:title="disconnect"
android:orderInCategory="101" />
</menu>
by: 发表于:2017-09-29 14:55:38 顶(0) | 踩(0) 回复
??
回复评论