Android 片段工具栏不显示菜单按钮
我有一个底部的导航,顶部有一个工具栏,我正试图显示一个播放菜单按钮。但它不会显示在底部工具栏上,而是显示在主工具栏上设置菜单所在的位置Android 片段工具栏不显示菜单按钮,android,Android,我有一个底部的导航,顶部有一个工具栏,我正试图显示一个播放菜单按钮。但它不会显示在底部工具栏上,而是显示在主工具栏上设置菜单所在的位置 CoordinatorLayout coordinatorLayout = (CoordinatorLayout) v.findViewById(R.id.bottom_sheet_coor); final View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) v.findViewById(R.id.bottom_sheet_coor);
final View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
final BottomSheetBehavior mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
Toolbar toolbar = (Toolbar) coordinatorLayout.findViewById(R.id.bottomToolBar);
setHasOptionsMenu(true);
上面的代码在片段中,下面是选项菜单方法:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_play, menu);
}
以下是菜单文件:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_play_bar"
android:orderInCategory="100"
android:icon="@drawable/ic_play_arrow"
android:title="@string/play_button"
app:showAsAction="always" />
</menu>
这是用于底部工作表导航的xml,我希望在其中显示工具栏:
<android.support.v7.widget.Toolbar
android:id="@+id/bottomToolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/colorPrimary">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginBottom="16dp"
android:gravity="center_horizontal"
android:text="Play now!"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>
如果您能提供有关它为什么显示在主导航抽屉工具栏而不是底部工具栏上的任何帮助,我们将不胜感激您在这里把事情搞混了。这就是你得到这个的原因 下面是一个示例代码块。将其放入任何框架布局中
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation" />
这里app:menu=“@menu/navigation”
应该像DrawerLayout
一样为这个小部件提供菜单。你不需要显式地膨胀它。现在把你的播放菜单项放到这个导航菜单中,瞧
onCreateOptions菜单(..)
用于将菜单添加到工具栏
希望这有帮助 你把这里的事情搞混了。这就是你得到这个的原因
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
下面是一个示例代码块。将其放入任何框架布局中
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation" />
这里app:menu=“@menu/navigation”
应该像DrawerLayout
一样为这个小部件提供菜单。你不需要显式地膨胀它。现在把你的播放菜单项放到这个导航菜单中,瞧
onCreateOptions菜单(..)
用于将菜单添加到工具栏
希望这有帮助
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
您没有在片段中编写此重写的方法。
希望这有帮助
您没有在片段中编写此重写的方法。
希望这有帮助