change the style of action mode

This commit is contained in:
houxg
2017-02-11 01:13:37 +08:00
parent f139d51c96
commit 1ebaabdbc8
3 changed files with 21 additions and 2 deletions

View File

@@ -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<T> {
@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<T> {
@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<T> {
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);

View File

@@ -15,4 +15,5 @@
<color name="divider_light">#1f000000</color>
<color name="navigation">#F5F5F5</color>
<color name="transparent">#00000000</color>
<color name="white">#FFFFFF</color>
</resources>

View File

@@ -11,11 +11,10 @@
<item name="windowActionBarOverlay">true</item>
<item name="android:homeAsUpIndicator">@drawable/ic_arrow_back_white</item>
<item name="actionModeStyle">@style/CustomActionMode</item>
<item name="android:actionModeCloseDrawable">@drawable/ic_arrow_back_white</item>
</style>
<style name="CustomActionMode" parent="@style/Widget.AppCompat.ActionMode">
<item name="background">@color/colorPrimaryDark</item>
<item name="background">@color/white</item>
<item name="height">?attr/actionBarSize</item>
</style>