From 1ebaabdbc8ceecf98a759e4556d2a0274f74593b Mon Sep 17 00:00:00 2001 From: houxg Date: Sat, 11 Feb 2017 01:13:37 +0800 Subject: [PATCH] change the style of action mode --- .../leamonax/utils/ActionModeHandler.java | 19 +++++++++++++++++++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/styles.xml | 3 +-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/houxg/leamonax/utils/ActionModeHandler.java b/app/src/main/java/org/houxg/leamonax/utils/ActionModeHandler.java index f946cc6..341b15a 100644 --- a/app/src/main/java/org/houxg/leamonax/utils/ActionModeHandler.java +++ b/app/src/main/java/org/houxg/leamonax/utils/ActionModeHandler.java @@ -2,11 +2,16 @@ package org.houxg.leamonax.utils; import android.app.Activity; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; +import android.os.Build; import android.support.annotation.MenuRes; import android.view.ActionMode; import android.view.Menu; import android.view.MenuItem; +import org.houxg.leamonax.R; + import java.util.ArrayList; import java.util.List; @@ -20,6 +25,14 @@ public class ActionModeHandler { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(mMenuId, menu); + Drawable drawable = menu.findItem(R.id.action_delete).getIcon(); + if (drawable != null) { + // If we don't mutate the drawable, then all drawable's with this id will have a color + // filter applied to it. + drawable.mutate(); + drawable.setColorFilter(mContext.getResources().getColor(R.color.colorPrimaryDark), PorterDuff.Mode.SRC_ATOP); + drawable.setAlpha(255); + } return true; } @@ -40,6 +53,9 @@ public class ActionModeHandler { @Override public void onDestroyActionMode(ActionMode mode) { mActionMode = null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mContext.getWindow().setStatusBarColor(mContext.getResources().getColor(R.color.colorPrimary)); + } mCallback.onDestroy(mPendingItems); } }; @@ -65,6 +81,9 @@ public class ActionModeHandler { return true; } } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mContext.getWindow().setStatusBarColor(mContext.getResources().getColor(R.color.colorPrimaryDark)); + } mActionMode = mContext.startActionMode(mActionCallback); mPendingItems = new ArrayList<>(); mPendingItems.add(item); diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 7a8c850..e58e904 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -15,4 +15,5 @@ #1f000000 #F5F5F5 #00000000 + #FFFFFF diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 2085409..1a78333 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -11,11 +11,10 @@ true @drawable/ic_arrow_back_white @style/CustomActionMode - @drawable/ic_arrow_back_white