From 2396de20a495768278e47d1f8e0b8ef55450e57c Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 1 Feb 2015 20:25:13 +0100 Subject: [PATCH] Action bar icon as up --- .../org/solovyev/android/calculator/ActivityUi.java | 7 +++++-- .../org/solovyev/android/calculator/BaseActivity.java | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java b/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java index 299ef765..bef6e466 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java @@ -94,13 +94,16 @@ public class ActivityUi extends BaseUi { onCreate((Activity) activity); final ActionBar actionBar = activity.getSupportActionBar(); actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(false); + final boolean homeAsUp = !(activity instanceof CalculatorActivity); + actionBar.setDisplayHomeAsUpEnabled(homeAsUp); actionBar.setHomeButtonEnabled(false); actionBar.setDisplayShowHomeEnabled(true); toggleTitle(activity, true); - actionBar.setIcon(R.drawable.ab_icon); + if (!homeAsUp) { + actionBar.setIcon(R.drawable.ab_icon); + } actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java index 4072e679..2fe6b971 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java @@ -3,6 +3,7 @@ package org.solovyev.android.calculator; import android.os.Bundle; import android.support.annotation.LayoutRes; import android.support.v7.app.ActionBarActivity; +import android.view.MenuItem; import javax.annotation.Nonnull; @@ -70,4 +71,14 @@ public class BaseActivity extends ActionBarActivity { super.onDestroy(); ui.onDestroy(this); } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } }