Search code examples
androidxmlandroid-toolbarmenuitem

Imageview is not visible when i set as src menu item of toolbar


I am so confused to see one thing over here why image view is not visible when i write `

android:src="@drawable/profile_icon"

but imageview is visible in menu item when i set background to it like

android:background="@drawable/profile_icon"

Is it because i have taken image in xml toolbar? please help me to set this one.

here is my XML please help me with this

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/etfields"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="center"
            android:background="#050b1f"
            android:gravity="center"
            app:titleTextColor="@color/white">

            <RelativeLayout
                android:id="@+id/main_toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/main_toolbar_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_centerInParent="true"
                    android:paddingRight="40dp"
                    android:text="My T-Shirt"
                    android:textColor="@color/white"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/logout"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="10dp"
                    android:background="@drawable/logout_icon"
                    android:paddingRight="40dp"
                    android:text=" "
                    android:textColor="@color/white"
                    android:textSize="18dp"
                    android:visibility="gone" />

                <TextView
                    android:id="@+id/notification"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="60dp"
                    android:background="@drawable/notification_icon"
                    android:paddingRight="45dp"
                    android:text=" "
                    android:textColor="@color/white"
                    android:textSize="18dp" />

                <ImageView
                    android:id="@+id/profileww"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="15dp"
                    android:visibility="visible"
                    android:background="@drawable/profile_icon"
                    android:paddingRight="40dp" />


            </RelativeLayout>


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

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"></FrameLayout>


</android.support.design.widget.CoordinatorLayout>

Solution

  • Just remove this line in your imageView it will work

    android:paddingRight="40dp"
    

    because background doesn't affected with paddding but when u set scr it will affect.

    Your image width and height is 25dp and you set padding as 40dp