Change Actionbar Menu Background

Asked

Viewed 1,070 times

1

Ola, there is some way to change in XML the background color of the options menu that appears in ActionBar?

  • You are already using the new Toolbar or even the old option for the ActionBar?

  • @Paulorodrigues I don’t really know how to answer your question, I think I’m using old, how do I see it?.. I’m using API 13

1 answer

0


You have two options:

1) If you are using the Toolbar (if not using, recommend), you can insert components into your Toolbar and stir as you like. For example:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:minHeight="?attr/actionBarSize"
    app:theme="@style/SeuTema"
    android:gravity="center_horizontal"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageButton
        android:id="@+id/img_exemplo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/sua_cor"
        android:src="@drawable/seu_icone" />

</android.support.v7.widget.Toolbar>

2) If you are not using the Toolbar, there is a way to "hack it" according to that post , and I will summarize it for you:

Menu items have various styles, ways, appearances etc. in several different manufacturers' Vices. There’s no documented way to do this. There are some options listed in the post, but are far from the ideal options for solving this problem, and on top of that does not work on all devices.

If you really need to have a background for your menu items, I suggest you study the implementation of Toolbar in your project not to have to face any unwanted "surprise". If so, follow the official documentation of how to implement them and there are some articles that can help you a lot in this.

  • 1

    Thanks! I will implement Toolbar @sicachester

  • @porthfind good! Any question post here we will help you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.