我遇到的問題是菜單按鈕未顯示在工具欄中。我將一個(gè)按鈕設(shè)置為始終顯示,將一個(gè)按鈕設(shè)置為僅在有空間時(shí)顯示。沒有顯示。這是使用 Android SDK 29 (Q) 編譯的。(我在 Stack Overflow 上搜索過類似的問題,但其他問題至少是幾年前寫的,并且使用的是較舊的 SDK。)activity_main.xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/tealBlue" tools:context=".view.MainActivity"> <androidx.appcompat.widget.Toolbar app:layout_constraintTop_toTopOf="parent" android:id="@+id/toolbar_top_main" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" android:theme="?attr/actionBarTheme" tools:menu="@menu/top_menu_overflow" /> <ExpandableListView android:id="@+id/expandableListViewPolls" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" android:indicatorLeft="? android:attr/expandableListPreferredItemIndicatorLeft" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@+id/toolbar_top_main" tools:layout_editor_absoluteX="16dp" /> ...
1 回答

慕少森
TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊
發(fā)現(xiàn)了問題。我需要在我的 MainActivity.java 中添加以下方法來擴(kuò)充菜單項(xiàng)。
@Override public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.top_menu_overflow, menu);
return true;
}
添加回答
舉報(bào)
0/150
提交
取消