Georgo
Georgo

Reputation: 51

menu icon not showing in toolbar

I try to add menu in toolbar.i wrote some code but i have very strange situation.i can't see menu image right side in my toolbar,but when i click it(i mean right side in toolbar)menu is showing this is a my source

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.unipay.business.activities.MainActivity">


    <item
        android:id="@+id/transaction_all"
        android:orderInCategory="100"
        android:title="@string/history_all"
        app:showAsAction="never" />
    <item
        android:id="@+id/transaction_Income"
        android:orderInCategory="100"
        android:title="@string/history_income"
        app:showAsAction="never" />
    <item
        android:id="@+id/transaction_Outcome"
        android:orderInCategory="100"
        android:title="@string/u_history_outcome"
        app:showAsAction="never" />
    <item
        android:id="@+id/transaction_advanced_search"
        android:orderInCategory="100"
        android:title="@string/u_history_advance"
        app:showAsAction="never" />

i ty to create like this menu

enter image description here

this is a my custom Toolbar layout xml code

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/u_common_header_height"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ToolbarTheme"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextAppearance="@style/Toolbar.TitleText">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/u_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="@dimen/u_sign_open_menu_margin"
        android:padding="@dimen/u_sign_open_menu_margin"
        android:src="@mipmap/ic_arrow_back_white" />


    <ImageView
        android:id="@+id/logo_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@mipmap/logo_header"
        android:visibility="gone" />

    <TextView
        android:id="@+id/header_tittle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginLeft="72dp"
        android:gravity="center"
        android:textColor="#ffffff"
        android:textSize="@dimen/u_common_text_size" />

</RelativeLayout>

I initialized my toolbar like this

 toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

this is a toolbar style

  <style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <!-- android:textColorPrimary is the color of the title text in the Toolbar  -->
    <item name="android:textColorPrimary">@android:color/holo_blue_light</item>
    <!-- actionMenuTextColor is the color of the text of action (menu) items  -->
    <item name="actionMenuTextColor">@android:color/holo_green_light</item>
    <!-- Tints the input fields like checkboxes and text fields -->
    <item name="colorAccent">@color/colorPrimary</item>
    <!-- Applies to views in their normal state. -->
    <item name="colorControlNormal">@color/colorPrimary</item>

    <item name="colorControlActivated">@color/colorPrimary</item>

    <item name="colorControlHighlight">@color/colorPrimary</item>
</style>


<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:textSize">21sp</item>
    <item name="android:textStyle">italic</item>
</style>

can anyone tell me what i'm doing wrong? as i said menu working in toolbar but i can't see menu image thanks

Upvotes: 3

Views: 5876

Answers (2)

Francisco Sales
Francisco Sales

Reputation: 121

try this

import android.support.v7.view.menu.MenuBuilder;

@SuppressLint("RestrictedApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (menu instanceof MenuBuilder) {
        ((MenuBuilder) menu).setOptionalIconsVisible(true);
    }
    getMenuInflater().inflate(R.menu.menu, menu);
    return super.onCreateOptionsMenu(menu);
}

Upvotes: 3

Sangram Haladkar
Sangram Haladkar

Reputation: 717

app:showAsAction="never"

change to app:showAsAction="always" or "ifRoom"

Upvotes: 0

Related Questions