5
我已经为我的操作栏实施了自定义视图。除此之外,我还需要一个OptionMenu。 有什么办法仍然使用默认的OptionMenu?我不想自己设计整个菜单&其功能。使用自定义操作栏/工具栏视图创建选项菜单
顺便说一句,我的活动来延长android.support.v7.app.AppCompatActivity
代码来实现自定义视图我动作条
custom_action_bar.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_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/custom_B"
android:layout_width="60dp"
android:layout_height="30dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
我将它包含在我的主XML中:
<include
layout="@layout/custom_action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
对于OptionsMenu我把一些木头,从来没有印刷
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.i(Constants.APP_NAME, "hello1");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.i(Constants.APP_NAME, "hello2");
}
我不知道是否可以使用默认OptionMenu与自定义actionBar。但是你可以创建自定义OptionMenu勾选这个[link](http://rajeshandroiddeveloper.blogspot.in/2013/07/android-popupwindow-example-in-listview.html) –
你有什么问题?由于您正在扩展工具栏,因此您应该可以使用“菜单”。显示你已经尝试了什么以及你有什么问题。 – JDenais
我要猜测并说你忘了在你的活动中调用setSupportActionBar()。如果你没有调用它,那么相关的菜单方法永远不会被调用(因为没用)。但是,你真的应该发布更多的活动代码。 – JDenais