Yasin Kaçmaz Yasin Kaçmaz - 1 year ago 72
Android Question

Android how to create fragment with X button

Hey community have a good day. I need to create some ui like that :

enter image description here

I tried : Create a fragment , create a dialog .

Assume that i have an activity A.I do some work in my activity then i start this "New event " ui.
I do some work and click "X" button and wanna continue from where i left in my activity A. So how i can do this . This layout is fragment or dialog ?

Answer Source

Actually we can create new activity and pass intent to it and change back icon like that :

final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {

And these 2 methods :

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            return true;


public void onBackPressed() {

Doing like that if we press back button or press X button previous activity will not recreate.