Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – Options Menu in MaterialSearchBar with NoActionBar – not showing the icons of overflow menu items and no action by clicking on item?

Posted on November 11, 2022 By

Solution 1 :

You don’t need to write onCreateOptionsMenu or onOptionsItemSelected method.

materialSearchBar.getMenu().setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()){
                case R.id.action_anleitung:
                    //Your Action
                    break;
                case R.id.action_fb:
                    //Your Action
                    break;
                default:
                    return true;
            }
        }
    });

Problem :

I hope someone can help me to solve this problem. I have an Activity with MaterialSearchBar and NoActionBar and I want to implement an options menu with items in it. The items should have their icons. So far I wrote the 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_anleitung"
                android_title="Anleitung"
                android_icon="@drawable/ic_manual"
                android_orderInCategory="100"
                app_showAsAction="never"/>
            <item
                android_id="@+id/action_fb"
                android_title="Feedback"
                android_icon="@drawable/ic_email"
                android_orderInCategory="100"
                app_showAsAction="never" />
</menu>

And added it to the Main.Activity:

  1. After my OnCreate-Method I added the following code: materialSearchBar.inflateMenu(R.menu.menu_main); and 2. added the following two methods:

    @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.menu_main, menu);
            return true;
        }
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_anleitung:
                    Toast.makeText(this, "Anleitung selected", Toast.LENGTH_SHORT).show();
                    return true;
                case R.id.action_fb:
                    Toast.makeText(this, "Feedback selected", Toast.LENGTH_SHORT).show();
                    return true;
                default:
                    return super.onOptionsItemSelected(item);
            }
        }
    

My problem is now the options menu is get showed and by clicking the overflow items get showed but:

  1. There are no icons near the item text “Anleitung” and “Feedback”. I added already icons-drawables so it’s not a problem.

  2. By clicking on the items there is no Toast with the text “Anleitung selected” or “Feedback selected”.

Did I miss something in the methods or codes? Or is it an issue of MaterialSearchBar which has another methods for options menu. I am trying to solve this problem since days and don’t find any solution
Thank you for helping out!

READ  [FIXED] java - Get Url from other apps android Studio
Powered by Inline Related Posts
Android Tags:android, java, optionmenu, uisearchbar

Post navigation

Previous Post: [FIXED] React Native floating animation
Next Post: [FIXED] java – maintain single database between customer and seller of android app

Related Posts

[FIXED] bluetooth lowenergy – BLE connection error on Android 6 (Marshmallow) – unable to marshal value BluetoothGattCharacteristic Android
[FIXED] Does adding “minifyEnabled true” and ‘proguard-android-optimize.txt’ obfuscate the sqlite database and make it incompatible with previous versions? Android
[FIXED] Changing ArrayList shown in RecyclerView Android Java Android
[FIXED] Check tab from activity to fragment in android Android
[FIXED] Can we use Android-Studio Translations Editor for Flutter? Android
[FIXED] java – Get error while login with facebook button on those mobile in which facebook Lite is installed Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme