what i am trying to implement is the ability for the user to search through the app. I want to do something like Youtube app as looks in the Screenshot below
The thing is that i dont know how to implement it into my app.
I have started with the options menu but for some reason the icon does not get displayed in the toolBar
My Code:
<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:activity=".ProductsNewOrder">
<item android:id="#+id/search"
android:title="#string/search"
android:visible="true"
android:icon="#android:drawable/ic_menu_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always" />
<item android:id="#+id/cart"
android:title="Cart"
android:visible="true"
android:icon="#drawable/abc_ic_menu_share_mtrl_alpha"
app:showAsAction="always" />
</menu>
The searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/search"
android:hint="#string/search" >
</searchable>
Manifest.xml
And where i create the options menu:
public class ProductsViewOrder extends FragmentActivity {
private ViewPager viewPager;
private ProductsTabPagerAdapter mAdapter;
private PagerSlidingTabStrip tabs;
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_order);
getActionBar().setElevation(0);
viewPager = (ViewPager) findViewById(R.id.pager);
Intent intent = getIntent();
String title = intent.getStringExtra("tableID");
getActionBar().setTitle(getString(R.string.table_id) + title);
mAdapter = new ProductsTabPagerAdapter(getSupportFragmentManager(), ProductsViewOrder.this, ProductsViewOrder.this);
viewPager.setAdapter(mAdapter);
tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
tabs.setViewPager(viewPager);
tabs.setDividerColor(Color.TRANSPARENT);
tabs.setIndicatorColor(Color.WHITE);
tabs.setIndicatorHeight(6);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_new_order, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.search:{
return true;
}
case R.id.cart:{
return true;
}
default:{
return super.onOptionsItemSelected(item);
}
}
}
private void showSearchResults() {
}
#Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.slide_out_left, R.anim.slide_in_left);
}
}
When i tap on search icon nothing happens.
Anyone can help me??
You can use PersistentSearch library link
Just a simple search with google :)
Related
I want to switch the icon in the actionbar on clicking to it.I did the following inside onOptionsItemSelected.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.star_School:
if (isStarFilled) {
item.setIcon(R.mipmap.starfilled);
isStarFilled=true;
}else{
item.setIcon(R.mipmap.star);
isStarFilled=false;
}
return true;
}
return super.onOptionsItemSelected(item);
}
This is not working in my case.This is my menu xml file
<?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/star_School"
android:icon="#mipmap/star"
android:title="Bookmark"
app:showAsAction="always" />
</menu>
This is my onCreate Method
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_school_details);
Boolean isStarFilled=false;
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(getIntent().getExtras().getString("name"));
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}
cannot resolve symbol isStarFilled?
Can somebody please help me?
Keep your icons in drawable and compare some thing like this
mRememberPwd.getDrawable().getConstantState().equals
(getResources().getDrawable(R.drawable.login_checked).getConstantState())
you can find more answers here on how to compare drawable
you can also try using flag
global variable
boolean isStarFilled=false;
case R.id.star_School:
if (isStarFilled) {
item.setIcon(R.mipmap.starfilled);
isStarFilled=false;
}else{
item.setIcon(R.mipmap.star);
isStarFilled=true;
}
return true;
I've been trying to add a functionality to my android application such that when I click a button, menu listing should be visible:
Here is my code:
menu.xml:
<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.example.MainActivity" >
<item android:id="#+id/action_onthego_sentence"
android:title="settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
From the main activity, upon clicking a button, I do:
button.setOnClickListener( new View.OnClickListener()
{
#Override
public void onClick( View view )
{
runOnUiThread( new Runnable()
{
#Override
public void run()
{
openOptionsMenu();
}
} );
}
} );
What I need is:
As shown in the image, I'd like to see the menu is opened. Any suggestions please?
If you are using customized toolbar in your app, then the following way will be useful,
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
toolbar.showOverflowMenu();
}
}, 500);
Use:
MainActivity.this.openOptionsMenu();
Then, check your toolbar if is this okay.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acercade_activity);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// MenuInflater inflater = getMenuInflater();
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
//case R.id.action_settings:
// return true;
case R.id.perfil:
drawerLayout.openDrawer(Gravity.LEFT);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Use this in your menu layout:
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="Setting"
app:showAsAction="ifRoom" />
Hello Dear if you are using toolbar following code
toolbar.showOverflowMenu();
And other wise you can directly call
MainActivity.this.openOptionsMenu();
Try the below solution It will be display click on the button menu listing should be visible:
res/menu/main.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">
<item
android:id="#+id/action_changeLang"
android:orderInCategory="100"
android:title="Change Lang" />
<item
android:id="#+id/action_color"
android:orderInCategory="100"
android:title="Select color" />
<item
android:id="#+id/action_applist"
android:orderInCategory="100"
android:title="App List" />
</menu>
MainActivity.java
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.action_changeLang:
// Add your code
break;
case R.id.action_color:
// Add your code
break;
case R.id.action_applist:
// Add your code
break;
}
return super.onOptionsItemSelected(item);
}
Try to use above solution. It will work for me
Use Activity.openOptionsMenu() to open menu programmatically, but you may need to post delay to call it. like below
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
openOptionsMenu();
}
}, 1000);
If you need to open sub menu automatically. you can call menu.performIdentifierAction after openOptionsMenu, like below
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
openOptionsMenu();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mainMenu.performIdentifierAction(R.id.submenu, 0);
}
}, 500);
}
}, 1000);
Android Dev efficiency tools: https://play.google.com/store/apps/details?id=cn.trinea.android.developertools
Android Open Source Projects: https://p.codekk.com/
I'm trying to add search icon to toolbar which pressed would open search bar.
But every method I tried didn't work and no icon appears.
Now I get this error and just can't find solution to it:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setOnQueryTextListener(android.support.v7.widget.SearchView$OnQueryTextListener)' on a null object reference
at pl.michalz.hideonscrollexample.activity.partthree.PartThreeActivity.onCreateOptionsMenu(PartThreeActivity.java:62)
This is my main Activity:
public class PartThreeActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppThemeBlue);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_part_three);
initToolbar();
initViewPagerAndTabs();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem seachItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView)
MenuItemCompat.getActionView(seachItem);
searchView.setOnQueryTextListener(
new SearchView.OnQueryTextListener(){
#Override
public boolean onQueryTextSubmit(String query) {
Log.d("myApp", "onQueryTextSubmit ");
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
Log.d("myApp", "onQueryTextChange ");
return false;
}
});
return true;
}
private void initToolbar() {
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
setTitle(getString(R.string.app_name));
mToolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
}
private void initViewPagerAndTabs() {
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager());
pagerAdapter.addFragment(PartThreeFragment.createInstance(), getString(R.string.tab_1));
pagerAdapter.addFragment(BlankFragment.createInstance("F word"), getString(R.string.tab_2));
viewPager.setAdapter(pagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout);
tabLayout.setupWithViewPager(viewPager);
}
static class PagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> fragmentList = new ArrayList<>();
private final List<String> fragmentTitleList = new ArrayList<>();
public PagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
public void addFragment(Fragment fragment, String title) {
fragmentList.add(fragment);
fragmentTitleList.add(title);
}
#Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
#Override
public int getCount() {
return fragmentList.size();
}
#Override
public CharSequence getPageTitle(int position) {
return fragmentTitleList.get(position);
}
}
//kai paskaudzia toolbaro iconas
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
// User chose the "Settings" item, show the app settings UI...
return true;
case R.id.action_search:
// User chose the "Favorite" action, mark the current item
// as a favorite...
return true;
default:
// If we got here, the user's action was not recognized.
// Invoke the superclass to handle it.
return super.onOptionsItemSelected(item);
}
}
}
main Activity.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/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:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap" />
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#android:color/white"
app:tabIndicatorHeight="6dp"
app:tabSelectedTextColor="#android:color/white"
app:tabTextColor="#android:color/white" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Also searchable.xml
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="#string/hint"
android:label="#string/app_name" />
And res/menu/menu_main.xml, added ic_search myself to drawable
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools">
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_search"
android:title="#string/action_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
<!-- Settings, should always be in the overflow -->
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never" />
</menu>
Could someone help?
I fixed error by changing namespace in menu_main.xml from app to my own myapp and it fixed automaticly by pressing "Alt+Enter".
res/menu/menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
//----------- it created automaticly --------------
xmlns:myapp="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_search"
android:title="#string/action_search"
//-------------- H E R E --------------------
myapp:showAsAction="always|collapseActionView"
myapp:actionViewClass="android.support.v7.widget.SearchView" />
<!-- Settings, should always be in the overflow -->
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never" />
</menu>
Main Activity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
Log.w("myApp", "onCreateOptionsMenu -started- ");
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
MenuItem menuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName()));
searchView.setQueryHint(getResources().getString(R.string.hint));
searchView.setOnQueryTextListener(
new SearchView.OnQueryTextListener(){
#Override
public boolean onQueryTextSubmit(String query) {
Log.w("myApp", "onQueryTextSubmit ");
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
Log.w("myApp", "onQueryTextChange ");
return false;
}
});
return true;
}
I faced the same problem. Solution is Simple.
Always check imports when doing alt+enter.
I did alt+enter and android.widget.SearchView got imported, whereas my implementation expected android.support.v7.widget.SearchView
In my app i inflate the action bar in Tabhost activity. Here actionbar dosn't displayed even i inflate using onCreateOptionsMenu(Menu menu)In follwing i have posted my code
TabhostActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#color/appblue">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
This is my menuItem.xml (Actionbar items)
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appmunu="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.after2.svirtzone.after2_gradle.UserDashBoardActivity">
<item
android:id="#+id/action_notify"
android:icon="#drawable/mail_icon"
appmunu:showAsAction="always"
android:title="Notification" />
<item
android:id="#+id/action_favourite"
android:icon="#drawable/favourite_icon"
appmunu:showAsAction="always"
android:title="Favourite" />
<item
android:id ="#+id/action_navigation"
android:icon="#drawable/ic_menu"
appmunu:showAsAction = "always"
android:title="navigation"
android:layout_gravity="left"/>
</menu>
This is my TabhostActivity
public class TabHostActivity extends TabActivity {
private Context context;
private static final String TAB_1_TAG = "AboutCollege";
private static final String TAB_2_TAG = "Focus of Course";
private static final String TAB_3_TAG = "Admision";
private static final String TAB_4_TAG = "Contact Details";
private static final String TAB_5_TAG = "Back";
#Override
protected void onStart() {
super.onStart();
AppActivityStatus.setActivityStarted();
AppActivityStatus.setActivityContext(context);
}
#Override
protected void onPause() {
super.onPause();
AppActivityStatus.setActivityStoped();
}
#Override
protected void onResume() {
super.onResume();
AppActivityStatus.setActivityStarted();
}
#Override
protected void onStop() {
super.onStop();
AppActivityStatus.setActivityStoped();
}
//here this the code for displaying the actionbar
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_user_dash_boad, menu);
return true;
}
// delete the selected event from event list added here
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_notify:
return true;
case R.id.action_favourite:
return true;
case R.id.action_navigation:
}
return super.onOptionsItemSelected(item);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_host);
context = getApplicationContext();
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
TabHost.TabSpec tag5= tabHost.newTabSpec(TAB_5_TAG);
TabHost.TabSpec tag4= tabHost.newTabSpec(TAB_4_TAG);
TabHost.TabSpec tag3= tabHost.newTabSpec(TAB_3_TAG);
TabHost.TabSpec tag2= tabHost.newTabSpec(TAB_2_TAG);
TabHost.TabSpec tag1= tabHost.newTabSpec(TAB_1_TAG);
tag1.setIndicator("", getResources().getDrawable(R.drawable.college_hover)).setContent(new Intent(this,AdmissionActivity.class));
tag2.setIndicator("", getResources().getDrawable(R.drawable.course)).setContent(new Intent(this, AboutCollegeActivity.class));
tag3.setIndicator("", getResources().getDrawable(R.drawable.admission)).setContent(new Intent(this, AboutCollegeActivity.class));
tag4.setIndicator("", getResources().getDrawable(R.drawable.contact)).setContent(new Intent(this, AboutCollegeActivity.class));
tag5.setIndicator("", getResources().getDrawable(R.drawable.back)).setContent(new Intent(this, AboutCollegeActivity.class));
tabHost.addTab(tag1);
tabHost.addTab(tag2);
tabHost.addTab(tag3);
tabHost.addTab(tag4);
}
}
In here Actionbar dosn't displayed but all other activites other than TabhostActivity it worked perfectly
Define a private variable of appcompatActivity first like these
private AppCompatActivity myact;
then add below lines inside your oncreate method
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
myact.setSupportActionBar(toolbar);
for api's below level 11
myact.getActionBar(toolbar);
I think this should solve the problem.See the root cause of this problem is your class is extending TabActivity not AppcompatActivity or Activity.So we have to specifically mention whether to show the Actionbar or not. I would recommend to use the Android Studio's standard Tabsliderview to design your application it is much easier to use and is well structured.
In my application I want to set a custom menu for the toolbar. The icon that I defined in the menu_settings.xml is an arrow, but when I start the application, it's a three-point menu instead of the arrow (as seen in the Pictures). After hours of research I still can't figure out why it loads this icon instead of the arrow (yes I checked the drawable ;) ). Thank you for solutions and hints!
SettingsActivity:
public class SettingsActivity extends PreferenceActivity {
private AppCompatDelegate mDelegate;
#Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
Intent intent = getIntent();
boolean hasConfiguredSettings = intent.getBooleanExtra(HAS_CONFIGURED_SETTINGS, false);
if (hasConfiguredSettings) {
toolbar.setTitle("Wähle deine Linien!");
} else {
// Back button in Toolbar
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
}
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(R.id.content, new SettingsFragment())
.commit();
}
private void setSupportActionBar(Toolbar toolbar) {
getDelegate().setSupportActionBar(toolbar);
}
private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
Intent intent = getIntent();
boolean hasConfiguredSettings = intent.getBooleanExtra("HAS_CONFIGURED_SETTINGS", false);
if (hasConfiguredSettings) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_settings, menu);
return true;
}
return false;
}
}
menu_settings.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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".SettingsActivity">
<item
android:id="#+id/action_checked"
android:orderInCategory="101"
android:title="#string/configuration_action_button"
app:showAsAction="always"
android:icon="#drawable/ic_action_arrow_right"/>
</menu>
toolbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/primary"
/>
The toolbar is included with:
<include
android:id="#+id/tool_bar"
layout="#layout/toolbar" />
You need to use AppCompatDelegate#getMenuInflater instead of Activity#getMenuInflater().
Replace the below line:
MenuInflater inflater = getMenuInflater();
with
MenuInflater inflater = getDelegate().getMenuInflater();