Yasin Kaçmaz Yasin Kaçmaz - 2 months ago 12
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

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) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.X_icon);
    }

And these 2 methods :

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

    return(super.onOptionsItemSelected(item));
}

@Override
public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(R.anim.nothing,R.anim.slide_out_right);
}

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

Comments