1.在学习 Android Support Library 23.2 中的 NavigationView 的使用时,想通过一个 按钮来手动增加侧滑菜单的 菜单项,但是应用 restart 之后这些增加的 "New Item" 就会丢失,如何保存这些增加的菜单项?
2.像图中这样的,通过 "Add New Item" 来增加 Menu Item
restart 之后
3.`
activity_main
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:headerLayout="@layout/nav_header"
app:menu="@menu/menu_nav">
<TextView
android:id="@+id/add_menu_item"
android:layout_width="match_parent"
android:layout_height="48dp"
android:textAllCaps="false"
android:clickable="true"
android:layout_gravity="bottom"
android:gravity="center"
android:textSize="20sp"
android:text="Add New Item"/>
</android.support.design.widget.NavigationView>`
MainActivity
tvAddItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
navDrawer.getMenu().add("New Item");
}
});
4.我是一名初学者,在搜索了好久之后自己实在无法做到,请大家帮帮忙!
Local storage and then add it, which probably means dynamic configuration, because the application will naturally be restored after it is reset. The basic approach is to use storage (database, configuration table, file) to record menu items, and then add them dynamically when the application starts.