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; ...@@ -8,8 +8,11 @@ import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button; import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
...@@ -72,8 +75,10 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb ...@@ -72,8 +75,10 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
private void startFragment(Fragment fragment) { private void startFragment(Fragment fragment) {
if (fragment instanceof MainFragment) { if (fragment instanceof MainFragment) {
currentFragment = FragmentConstants.MAIN_FRAGMENT; currentFragment = FragmentConstants.MAIN_FRAGMENT;
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
} else { } else {
currentFragment = FragmentConstants.APP_SETTINGS_FRAGMENT; currentFragment = FragmentConstants.APP_SETTINGS_FRAGMENT;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
Log.d(TAG, "startFragment: " + currentFragment); Log.d(TAG, "startFragment: " + currentFragment);
...@@ -170,4 +175,15 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb ...@@ -170,4 +175,15 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
else else
return 0; 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