How to have activity in Android with a close button at the top corner?

后端 未结 4 1326
长发绾君心
长发绾君心 2020-12-08 23:43

I would like to have an activity which would consist of a close button i.e \'x\' at the right top corner closing the activity. Any examples on this will be very much helpful

4条回答
  •  忘掉有多难
    2020-12-09 00:18

    Use juzt have an x like image at the right top of corner. By pressing x image u can finish the activity.

    XML:

            
    

    In Java Code:

           ImageView view=(ImageView)findViewById(R.id.close);
           view.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View arg0) {
                 Intent intent=new Intent(currentclass.this,statingclass.class);
                  startActivity(intent);// here u can start another activity or just call finish method to close the activity.
                  finish();
    
            }
        });
    

提交回复
热议问题