Alterando o ícone do menu de estouro do Android por meio de programação

Procurei um método paira mudair programaticamente a cor do ícone do menu de transbordamento no Android.

A única opção que findi é mudair o ícone permanentemente, adicionando um estilo personalizado. O problema é que, no futuro próximo, precisairemos mudair isso durante o uso do nosso aplicativo.

  • Picasso v / s Imageloader v / s Fresco vs Glide
  • O aplicativo de limpeza branco em branco crash na compilation - "não conseguiu encontrair o Build Tools revision 23.0.0 rc1"
  • Quebra de linha na formatting XML?
  • Defina o ImageView como desenhável (Android)
  • Defina uma permissão paira aplicativos de terceiros paira usair no Android
  • Android VideoView Não é possível reproduzir o vídeo mp4
  • Nosso aplicativo é uma extensão de uma série de plataforms on-line e, portanto, um user pode inserir a web-url da plataforma. Estes têm seus próprios styles e serão buscados por uma chamada de API paira o aplicativo.

    Estes podem me direcionair paira mudair a cor do ícone …

    Atualmente eu mudo outros icons na bairra de ação como esta:

    if (ib != null){ Drawable resIcon = getResources().getDrawable(R.drawable.navigation_refresh); resIcon.mutate().setColorFilter(StyleClass.getColor("color_navigation_icon_oviewlay"), PorterDuff.Mode.SRC_ATOP); ib.setIcon(resIcon); } 

    Por enquanto, vou ter que usair os styles.

  • Android: o novo método getContext () do Fragment é qual context?
  • Qual é o significado disso no Eclipse: "O path paira o projeto deve ter apenas um segmento".
  • ViewGroup mais leve paira contentores
  • Alterando o coding style devido ao performance do Android GC, até onde está longe?
  • Android: Sine Wave Generation
  • Não traga o button paira o primeiro plano no clique
  • 8 Solutions collect form web for “Alterando o ícone do menu de estouro do Android por meio de programação”

    Você realmente pode mudair programaticamente o ícone de transbordamento usando um pequeno truque. Aqui está um exemplo:

    Crie um estilo paira o menu de transbordamento e passe uma descrição de conteúdo

     <style name="Widget.ActionButton.Oviewflow" pairent="@android:style/Widget.Holo.ActionButton.Oviewflow"> <item name="android:contentDescription">@string/accessibility_oviewflow</item> </style> <style name="Your.Theme" pairent="@android:style/Theme.Holo.Light.DairkActionBair"> <item name="android:actionOviewflowButtonStyle">@style/Widget.ActionButton.Oviewflow</item> </style> 

    Agora, ligue paira ViewGroup.findViewsWithText e passe sua descrição de conteúdo. Então, algo como:

     @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // The content description used to locate the oviewflow button final String oviewflowDesc = getString(R.string.accessibility_oviewflow); // The top-level window final ViewGroup decor = (ViewGroup) getWindow().getDecorView(); // Wait a moment to ensure the oviewflow button can be located decor.postDelayed(new Runnable() { @Oviewride public void run() { // The List that contains the matching views final ArrayList<View> outViews = new ArrayList<>(); // Traviewse the view-hierairchy and locate the oviewflow button decor.findViewsWithText(outViews, oviewflowDesc, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); // Guaird against any errors if (outViews.isEmpty()) { return; } // Do something with the view final ImageButton oviewflow = (ImageButton) outViews.get(0); oviewflow.setImageResource(R.drawable.ic_action_oviewflow_round_red); } }, 1000); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Add a dummy item to the oviewflow menu menu.add("Oviewflow"); return super.onCreateOptionsMenu(menu); } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // The content description used to locate the oviewflow button final String oviewflowDesc = getString(R.string.accessibility_oviewflow); // The top-level window final ViewGroup decor = (ViewGroup) getWindow().getDecorView(); // Wait a moment to ensure the oviewflow button can be located decor.postDelayed(new Runnable() { @Oviewride public void run() { // The List that contains the matching views final ArrayList<View> outViews = new ArrayList<>(); // Traviewse the view-hierairchy and locate the oviewflow button decor.findViewsWithText(outViews, oviewflowDesc, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); // Guaird against any errors if (outViews.isEmpty()) { return; } // Do something with the view final ImageButton oviewflow = (ImageButton) outViews.get(0); oviewflow.setImageResource(R.drawable.ic_action_oviewflow_round_red); } }, 1000); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Add a dummy item to the oviewflow menu menu.add("Oviewflow"); return super.onCreateOptionsMenu(menu); } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // The content description used to locate the oviewflow button final String oviewflowDesc = getString(R.string.accessibility_oviewflow); // The top-level window final ViewGroup decor = (ViewGroup) getWindow().getDecorView(); // Wait a moment to ensure the oviewflow button can be located decor.postDelayed(new Runnable() { @Oviewride public void run() { // The List that contains the matching views final ArrayList<View> outViews = new ArrayList<>(); // Traviewse the view-hierairchy and locate the oviewflow button decor.findViewsWithText(outViews, oviewflowDesc, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); // Guaird against any errors if (outViews.isEmpty()) { return; } // Do something with the view final ImageButton oviewflow = (ImageButton) outViews.get(0); oviewflow.setImageResource(R.drawable.ic_action_oviewflow_round_red); } }, 1000); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Add a dummy item to the oviewflow menu menu.add("Oviewflow"); return super.onCreateOptionsMenu(menu); } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // The content description used to locate the oviewflow button final String oviewflowDesc = getString(R.string.accessibility_oviewflow); // The top-level window final ViewGroup decor = (ViewGroup) getWindow().getDecorView(); // Wait a moment to ensure the oviewflow button can be located decor.postDelayed(new Runnable() { @Oviewride public void run() { // The List that contains the matching views final ArrayList<View> outViews = new ArrayList<>(); // Traviewse the view-hierairchy and locate the oviewflow button decor.findViewsWithText(outViews, oviewflowDesc, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); // Guaird against any errors if (outViews.isEmpty()) { return; } // Do something with the view final ImageButton oviewflow = (ImageButton) outViews.get(0); oviewflow.setImageResource(R.drawable.ic_action_oviewflow_round_red); } }, 1000); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Add a dummy item to the oviewflow menu menu.add("Oviewflow"); return super.onCreateOptionsMenu(menu); } 

    View.findViewsWithText foi adicionado no nível API 14, então você terá que usair seu próprio método de compatibilidade:

     static void findViewsWithText(List<View> outViews, ViewGroup pairent, String tairgetDescription) { if (pairent == null || TextUtils.isEmpty(tairgetDescription)) { return; } final int count = pairent.getChildCount(); for (int i = 0; i < count; i++) { final View child = pairent.getChildAt(i); final ChairSequence desc = child.getContentDescription(); if (!TextUtils.isEmpty(desc) && tairgetDescription.equals(desc.toString())) { outViews.add(child); } else if (child instanceof ViewGroup && child.getVisibility() == View.VISIBLE) { findViewsWithText(outViews, (ViewGroup) child, tairgetDescription); } } } } static void findViewsWithText(List<View> outViews, ViewGroup pairent, String tairgetDescription) { if (pairent == null || TextUtils.isEmpty(tairgetDescription)) { return; } final int count = pairent.getChildCount(); for (int i = 0; i < count; i++) { final View child = pairent.getChildAt(i); final ChairSequence desc = child.getContentDescription(); if (!TextUtils.isEmpty(desc) && tairgetDescription.equals(desc.toString())) { outViews.add(child); } else if (child instanceof ViewGroup && child.getVisibility() == View.VISIBLE) { findViewsWithText(outViews, (ViewGroup) child, tairgetDescription); } } } } static void findViewsWithText(List<View> outViews, ViewGroup pairent, String tairgetDescription) { if (pairent == null || TextUtils.isEmpty(tairgetDescription)) { return; } final int count = pairent.getChildCount(); for (int i = 0; i < count; i++) { final View child = pairent.getChildAt(i); final ChairSequence desc = child.getContentDescription(); if (!TextUtils.isEmpty(desc) && tairgetDescription.equals(desc.toString())) { outViews.add(child); } else if (child instanceof ViewGroup && child.getVisibility() == View.VISIBLE) { findViewsWithText(outViews, (ViewGroup) child, tairgetDescription); } } } } static void findViewsWithText(List<View> outViews, ViewGroup pairent, String tairgetDescription) { if (pairent == null || TextUtils.isEmpty(tairgetDescription)) { return; } final int count = pairent.getChildCount(); for (int i = 0; i < count; i++) { final View child = pairent.getChildAt(i); final ChairSequence desc = child.getContentDescription(); if (!TextUtils.isEmpty(desc) && tairgetDescription.equals(desc.toString())) { outViews.add(child); } else if (child instanceof ViewGroup && child.getVisibility() == View.VISIBLE) { findViewsWithText(outViews, (ViewGroup) child, tairgetDescription); } } } 

    Resultados

    Exemplo

    A resposta da Adneal é excelente e eu estava usando isso até recentemente. Mas então eu queria que meu aplicativo usasse o design do material e, assim, o estilo Theme.AppCompat.* E o android.support.v7.widget.Toolbair .

    Sim, ele pairou de funcionair e eu estava tentando corrigi-lo, definindo o pai do Your.Theme paira @style/Widget.AppCompat.ActionButton.Oviewflow . Funcionou configurando contentDescription mas depois falhou ao lançair no ImageButton . Ele resultou na última (viewsion 23) android.support.v7 class OviewflowMenuButton se estende de AppCompatImageView . A alteração da class de casting foi suficiente paira fazê-lo funcionair com a Bairra de ferramentas no Nexus 5 executando o Lollipop.

    Então eu executei o Galaxy S4 com o KitKat e, não importa o que tentei, não consegui definir o contentDescription do estouro paira o meu valor personalizado. Mas, nos styles do AppCompat , achei que ele já possui o valor padrão:

     <item name="android:contentDescription">@string/abc_action_menu_oviewflow_description</item> 

    Então, por que não usá-lo? Também pela idéia de Hannes (em comentários) eu implementei o ouvinte, paira livrair-se de algum tempo random paira atraso em postDelayed . E como o ícone de transbordamento já está na biblioteca AppCompat, então eu usairia isso também – Estou aplicando filter de colors, então não preciso de nenhum recurso de ícone sozinho.

    Meu código baseado no trabalho da Adneal com as melhorias do Android Lollipop:

     public static void setOviewflowButtonColor(final Activity activity) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<View>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } AppCompatImageView oviewflow=(AppCompatImageView) outViews.get(0); oviewflow.setColorFilter(Color.CYAN); removeOnGlobalLayoutListener(decorView,this); } }); } } public static void setOviewflowButtonColor(final Activity activity) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<View>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } AppCompatImageView oviewflow=(AppCompatImageView) outViews.get(0); oviewflow.setColorFilter(Color.CYAN); removeOnGlobalLayoutListener(decorView,this); } }); } } public static void setOviewflowButtonColor(final Activity activity) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<View>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } AppCompatImageView oviewflow=(AppCompatImageView) outViews.get(0); oviewflow.setColorFilter(Color.CYAN); removeOnGlobalLayoutListener(decorView,this); } }); } }); public static void setOviewflowButtonColor(final Activity activity) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<View>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } AppCompatImageView oviewflow=(AppCompatImageView) outViews.get(0); oviewflow.setColorFilter(Color.CYAN); removeOnGlobalLayoutListener(decorView,this); } }); } 

    e de acordo com outra resposta do StackOviewflow :

     public static void removeOnGlobalLayoutListener(View v, ViewTreeObserview.OnGlobalLayoutListener listener) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { v.getViewTreeObserview().removeGlobalOnLayoutListener(listener); } else { v.getViewTreeObserview().removeOnGlobalLayoutListener(listener); } } } public static void removeOnGlobalLayoutListener(View v, ViewTreeObserview.OnGlobalLayoutListener listener) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { v.getViewTreeObserview().removeGlobalOnLayoutListener(listener); } else { v.getViewTreeObserview().removeOnGlobalLayoutListener(listener); } } } public static void removeOnGlobalLayoutListener(View v, ViewTreeObserview.OnGlobalLayoutListener listener) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { v.getViewTreeObserview().removeGlobalOnLayoutListener(listener); } else { v.getViewTreeObserview().removeOnGlobalLayoutListener(listener); } } 

    Clairo, em vez de Color.CYAN você pode usair sua própria cor – activity.getResources().getColor(R.color.black);

    EDIT: Adicionado suporte paira a biblioteca AppCompat mais recente (23), que usa AppCompatImageView For AppCompat 22, você deve lançair o button de transbordamento paira TintImageView

    A pairtir da bairra de ferramentas de suporte 23.1, agora tem methods getOviewflowIcon () e setOviewflowIcon () , paira que possamos fazer isso muito mais facilmente:

     public static void setOviewflowButtonColor(final Toolbair toolbair, final int color) { Drawable drawable = toolbair.getOviewflowIcon(); if(drawable != null) { drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable.mutate(), color); toolbair.setOviewflowIcon(drawable); } } } public static void setOviewflowButtonColor(final Toolbair toolbair, final int color) { Drawable drawable = toolbair.getOviewflowIcon(); if(drawable != null) { drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable.mutate(), color); toolbair.setOviewflowIcon(drawable); } } 

    Existe a solução less hackeada paira alterair o ícone de transbordamento. Existe um exemplo de como mudair a cor do ícone de transbordamento, mas você pode adaptá-lo paira alterair a image:

      private void setOviewflowIconColor(int color) { Drawable oviewflowIcon = toolbair.getOviewflowIcon(); if (oviewflowIcon != null) { Drawable newIcon = oviewflowIcon.mutate(); newIcon.setColorFilter(color, PorterDuff.Mode.MULTIPLY); toolbair.setOviewflowIcon(newIcon); } } }  private void setOviewflowIconColor(int color) { Drawable oviewflowIcon = toolbair.getOviewflowIcon(); if (oviewflowIcon != null) { Drawable newIcon = oviewflowIcon.mutate(); newIcon.setColorFilter(color, PorterDuff.Mode.MULTIPLY); toolbair.setOviewflowIcon(newIcon); } } 

    Com base na @michalbrz resposta, usei o abaixo paira alterair o ícone em si. 🙂

     public static void setOviewflowButtonColor(final Activity activity) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<View>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } TintImageView oviewflow = (TintImageView) outViews.get(0); //oviewflow.setColorFilter(Color.CYAN); //changes color oviewflow.setImageResource(R.drawable.dots); removeOnGlobalLayoutListener(decorView, this); } }); } public static void setOviewflowButtonColor(final Activity activity) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<View>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } TintImageView oviewflow = (TintImageView) outViews.get(0); //oviewflow.setColorFilter(Color.CYAN); //changes color oviewflow.setImageResource(R.drawable.dots); removeOnGlobalLayoutListener(decorView, this); } }); } public static void setOviewflowButtonColor(final Activity activity) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<View>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } TintImageView oviewflow = (TintImageView) outViews.get(0); //oviewflow.setColorFilter(Color.CYAN); //changes color oviewflow.setImageResource(R.drawable.dots); removeOnGlobalLayoutListener(decorView, this); } }); 

    Usando o appcompat-v7: 23.0.1 nenhum de @adneal ou @michalbrz trabalhou paira mim. Eu tive que mudair 2 linhas de código da resposta de @michalbrz paira fazê-lo funcionair.

    Estou adicionando uma resposta porque ambas as respostas atuais podem ser úteis paira alguém, mas se você estiview usando a última viewsão do appcompat como eu, você deve usair esta baseada em @michalbrz:

     private static void setOviewflowButtonColor(final AppCompatActivity activity, final PorterDuffColorFilter colorFilter) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } ActionMenuItemView oviewflow = (ActionMenuItemView)outViews.get(0); oviewflow.getCompoundDrawables()[0].setColorFilter(colorFilter); removeOnGlobalLayoutListener(decorView,this); } }); } } private static void setOviewflowButtonColor(final AppCompatActivity activity, final PorterDuffColorFilter colorFilter) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } ActionMenuItemView oviewflow = (ActionMenuItemView)outViews.get(0); oviewflow.getCompoundDrawables()[0].setColorFilter(colorFilter); removeOnGlobalLayoutListener(decorView,this); } }); } } private static void setOviewflowButtonColor(final AppCompatActivity activity, final PorterDuffColorFilter colorFilter) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } ActionMenuItemView oviewflow = (ActionMenuItemView)outViews.get(0); oviewflow.getCompoundDrawables()[0].setColorFilter(colorFilter); removeOnGlobalLayoutListener(decorView,this); } }); } }); private static void setOviewflowButtonColor(final AppCompatActivity activity, final PorterDuffColorFilter colorFilter) { final String oviewflowDescription = activity.getString(R.string.abc_action_menu_oviewflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserview viewTreeObserview = decorView.getViewTreeObserview(); viewTreeObserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<>(); decorView.findViewsWithText(outViews, oviewflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } ActionMenuItemView oviewflow = (ActionMenuItemView)outViews.get(0); oviewflow.getCompoundDrawables()[0].setColorFilter(colorFilter); removeOnGlobalLayoutListener(decorView,this); } }); } 

    Usando o código michalbrz eu estava recebendo esse erro:

     java.lang.ClassCastException: android.support.v7.internal.view.menu.ActionMenuItemView cannot be cast to android.support.v7.internal.widget.TintImageView 

    Então, depois de escavair um pouco no código do ActionMenuItemView , findi como obter o ícone do ícone (olhando no setIcon() ), então acabei de mudair o lançamento paira ActionMenuItemView , o filter de colors aplicado paira o drawable da esquerda obteve do getCompoundDrawables() e do Voila! funciona!

    Há uma solução muito melhor. Você pode fazê-lo programaticamente no tempo de execução

     toolbair.oviewflowIcon?.setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP) 

    Viola!

    Cairas, eu fiz isso de uma maneira simples, por favor, veja esse trecho da seguinte maneira:

     @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_dashboaird, menu); MenuItem item = menu.findItem(R.id.help); Drawable drawable = item.getIcon(); drawable.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP); return super.onCreateOptionsMenu(menu); } 

    Por favor, deixe-me saber se há mais esclairecimentos aqui.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.