码迷,mamicode.com
首页 > 移动开发 > 详细

android资源:菜单和assets

时间:2015-07-24 10:27:41      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

1、菜单(menu)

1、menu\menu.xml中定义

技术分享
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.mytest.testbase.MainActivity" >

    <item
        android:id="@+id/showDialog"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="dialog"/>
    
    <item
        android:id="@+id/showToast"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="toast"/>    
</menu>
View Code

 

2、activity中代码

技术分享
    @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);

android资源:菜单和assets

标签:

原文地址:http://www.cnblogs.com/2015android/p/4672615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!