I have two buttons one provides search functionality and the other one shows a print button. The search button is showing perfectly but the Imageviewbutton is not showing an image just a small dot is display
here is my code what exactly I am making a mistake
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_filter"
app:showAsAction="always"
android:title="Filter"
android:visible="false"
android:orderInCategory="2"
android:icon="@drawable/ic_tune_black_24dp" />
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search"
android:title="@string/action_search"
android:orderInCategory="0"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always" />
<item
android:id="@+id/action_print"
android:icon="@drawable/print"
android:title="Print"
android:orderInCategory="1"
android:visible="true"
app:actionViewClass="android.support.v7.widget.AppCompatImageButton"
app:showAsAction="always" />
</menu>
It seems that the AppCompatImageButton might not be the best choice for displaying an action item in the toolbar/menu. Instead, you should use the standard ImageView for the icon display. Also, make sure the drawable resource exists and is correctly referenced.
Here’s an updated version of your menu XML that uses ImageView for the print button:
Updated menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Search Item -->
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search"
android:title="@string/action_search"
android:orderInCategory="0"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="always" />
<!-- Filter Item -->
<item
android:id="@+id/menu_filter"
app:showAsAction="always"
android:title="Filter"
android:visible="false"
android:orderInCategory="2"
android:icon="@drawable/ic_tune_black_24dp" />
<!-- Print Item -->
<item
android:id="@+id/action_print"
android:icon="@drawable/ic_print" <!-- Ensure this drawable exists -->
android:title="Print"
android:orderInCategory="1"
android:visible="true"
app:showAsAction="always" />