Verified Commit cddbc2b4 authored by HashikD's avatar HashikD
Browse files

Added up(back) button

parent 6a19850c
......@@ -8,8 +8,11 @@ import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
......@@ -72,8 +75,10 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
private void startFragment(Fragment fragment) {
if (fragment instanceof MainFragment) {
currentFragment = FragmentConstants.MAIN_FRAGMENT;
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
} else {
currentFragment = FragmentConstants.APP_SETTINGS_FRAGMENT;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
Log.d(TAG, "startFragment: " + currentFragment);
......@@ -170,4 +175,15 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
else
return 0;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment