每日总结3.7

安卓开发菜单栏

首先在想xml文件里引入Toobar控件,他的作用就是制作一个顶部菜单,但是想要对这个菜单有操作需要以下代码

 myToolbar=findViewById(R.id.myToolbar);
 setSupportActionBar(myToolbar);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

想要对原始界面的返回键设置菜单则可用此函数,作用就是设置图标相关的操作。

   myToolbar.setNavigationIcon(R.drawable.ic_menu_black_24dp);

对菜单栏里面设置单击事件

复制代码
  myToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(openMode == 4||flag){
                    if(et.getText().toString().length() == 0){
                        intent.putExtra("mode", -1); //nothing new happens.
                    }
                    else{
                        intent.putExtra("mode", 0); // new one note;
                        intent.putExtra("content", et.getText().toString());
                        intent.putExtra("time", dataToStr());
                        intent.putExtra("tag", tag);
                    }
                }
                else {
                    if (et.getText().toString().equals(old_content)&&!tagChange)
                        intent.putExtra("mode", -1); // edit nothing
                    else {
                        intent.putExtra("mode", 1); //edit the content
                        intent.putExtra("content", et.getText().toString());
                        intent.putExtra("time", dataToStr());
                        intent.putExtra("id", id);
                        intent.putExtra("tag", tag);
                    }
                }
                setResult(RESULT_OK, intent);
                finish();





            }
        });
复制代码

 

posted @   cojames  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示