0

I am trying to implement android Toolbar as action bar. My action bar should contain one logo as header and an overflow menu. Overflow menu icon color is green. I used a widget OverflowMenuButton but some exception is coming after adding this. I don't know how to correctly use this widget.

Here is my code

<android.support.v7.widget.Toolbar  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="@color/white"
android:gravity="center">
<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="false"
    android:focusable="false"
    android:longClickable="false"
    android:src="@drawable/logo_multi"/>
  <OverflowMenuButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/green"/>

 </android.support.v7.widget.Toolbar>

I am posting some of the error lines

at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class OverflowMenuButton
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
         at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
        at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
        at com.ragpicker.screen.StartScreen.onCreate(StartScreen.java:35)
        at android.app.Activity.performCreate(Activity.java:5541)
  Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.OverflowMenuButton" on path: DexPathList[[zip file "/data/app/com.ragpicker-669.apk"],nativeLibraryDirectories=[/data/app-lib/com.ragpicker-669, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
        at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)

           In oncreate,

 setContentView(R.layout.screen_startscreen);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }
n1m1
  • 869
  • 1
  • 9
  • 20

1 Answers1

0

I found solution1 and solution2 to this problem:

1- don't call setSupportActionBar(mToolbar); any more, instead use Toolbar directly

2- check if device has a hardware menu button by calling ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(getApplicationContext()));

3- if device has menu button i return true on in onCreateOptionsMenu, else i inflate the menu in the Toolbar

Community
  • 1
  • 1
Amrut Bidri
  • 6,276
  • 6
  • 38
  • 80
  • 1
    sorry, my question is about **OverflowMenuButton widget** not about hardware menu button. – n1m1 Mar 03 '15 at 09:05
  • OverflowMenuButton i cant find any references to this class. can you send documentation link for this class from android developers site?. – Amrut Bidri Mar 03 '15 at 09:10