我正在尝试将android工具栏作为操作栏实现。我的操作栏应包含一个徽标作为标题和溢出菜单。溢出菜单图标颜色为绿色。我使用了一个小部件 OverflowMenuButton 但添加此内容后会出现一些异常。我不知道如何正确使用这个小部件。
这是我的代码
<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>
我发布了一些错误行
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)
在oncreate中,
setContentView(R.layout.screen_startscreen);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
}