AI2 Component  (Version nb184)
ImageViewUtil.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2017-2020 MIT, All rights reserved
3 // Released under the Apache License, Version 2.0
4 // http://www.apache.org/licenses/LICENSE-2.0
5 
6 package com.google.appinventor.components.runtime.util;
7 
8 import static android.graphics.PorterDuff.Mode.MULTIPLY;
9 
10 import android.app.Activity;
11 import android.content.res.ColorStateList;
12 import android.view.View;
13 import android.view.ViewGroup;
14 import android.widget.ImageView;
15 import androidx.core.widget.ImageViewCompat;
16 import java.util.LinkedList;
17 import java.util.Queue;
18 
19 public final class ImageViewUtil {
20 
26  private ImageViewUtil() {}
27 
28  public static void setMenuButtonColor(Activity activity, int color) {
29  ColorStateList stateList = new ColorStateList(new int[][]{new int[]{}}, new int[]{color});
30  ImageView view = findOverflowMenuView(activity);
31  if (view != null) {
32  ImageViewCompat.setImageTintMode(view, MULTIPLY);
33  ImageViewCompat.setImageTintList(view, stateList);
34  }
35  }
36 
37  private static ImageView findOverflowMenuView(Activity activity) {
38  ViewGroup vg = (ViewGroup) activity.getWindow().getDecorView();
39  Queue<ViewGroup> children = new LinkedList<ViewGroup>();
40  children.add(vg);
41  while (children.size() > 0) {
42  vg = children.poll();
43  for (int i = 0; i < vg.getChildCount(); i++) {
44  View child = vg.getChildAt(i);
45  if (child instanceof ImageView) {
46  return (ImageView) child;
47  } else if (child instanceof ViewGroup) {
48  children.add((ViewGroup) child);
49  }
50  }
51  }
52  return null;
53  }
54 }
com.google.appinventor.components.runtime.util.ImageViewUtil.setMenuButtonColor
static void setMenuButtonColor(Activity activity, int color)
Definition: ImageViewUtil.java:28
com.google.appinventor.components.runtime.util.ImageViewUtil
Definition: ImageViewUtil.java:19