您的位置:首页 > 移动开发 > Android开发

android资源:菜单和assets

2015-07-24 10:12 567 查看
1、菜单(menu)

1、menu\menu.xml中定义

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

int id = item.getItemId();
if (id == R.id.showDialog) {
new AlertDialog.Builder(this).setTitle("测试").setPositiveButton("关闭", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

Toast.makeText(MainActivity.this, "showDialog", Toast.LENGTH_SHORT).show();
}
}).show();
}    if (id == R.id.showToast) {
Toast.makeText(this, "toast", Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}


View Code

二、assets资源读取
1、在assets中放置文件.

2、activity中读取
InputStream is = getBaseContext().getAssets().open(DBService.DB_NAME);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: