Show an imageview instead of icon on toolbar options menu

When you override the onCreateOptionsMenu() you get a options menu which opens when you click the 3 dot icon on top right. I want to show a circular image view with image of a user instead of the 3 dot icon. How do I do this?

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
    menuInflater.inflate(R.menu.options_menu, menu);
    return true
}

1 answer

  • answered 2020-02-16 17:52 Chetan Garg

    Hi @Amol you can learn more about the toolbar from codepath guide,

    try to replace toolbar

    <androidx.appcompat.widget.Toolbar
           android:layout_width="match_parent"
           android:layout_height="wrap_content">
    
            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                <androidx.appcompat.widget.AppCompatImageView
                    android:layout_marginTop="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_gravity="end"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:srcCompat="@mipmap/ic_launcher_round" />
    
            </FrameLayout>
    
    
    </androidx.appcompat.widget.Toolbar>
    
    

    if you just want to replace the icon and still keep overflow menu read from the similar answer from this