icon cannot show in actionbar, this is my search.xml in menu folder
<?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/search"
android:icon="@drawable/ic_search_orange_24dp"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="androidx.appcompat.widget.SearchView"
android:title="Search"/>
<item
android:id="@+id/chat"
android:icon="@drawable/ic_message_black_24dp"
app:showAsAction="ifRoom"
android:title="Message"/>
</menu>
https://i.sstatic.net/oQVXn.png
but, it cannot show in the app
https://i.sstatic.net/VLHAP.png
this is fragment_home.xml
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
app:titleTextColor="#007FFF"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="IFUNPOT" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_below="@+id/appbar"
android:id="@+id/recy_feed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
/>
this is Homefragment.java
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.search,menu);
super.onCreateOptionsMenu(menu, inflater);
}
this is MainActivity.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search, menu);
return true;
}
so....where is problem?
who knows where has problem?
You might have forgotten to use setHasOptionsMenu(true)
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
If you use toolbar, you might have to set up the toolbar in your activity as well in your activity's onCreate setSupportActionBar(toolbar)
.