我的应用程序中有一个导航抽屉。我想在导航抽屉菜单的第二部分中以编程方式添加选项。 menu.xml是 -
<group android:checkableBehavior="single">
<item android:id="@+id/nav_connect_sensor"
android:icon="@drawable/ic_action_bluetooth"
android:title="Connect Bluetooth" />
<item android:id="@+id/nav_take_tour"
android:icon="@drawable/ic_action_video"
android:title="Take a tour" />
<item android:id="@+id/nav_my_stats"
android:icon="@drawable/ic_action_bargraph"
android:title="My Stats" />
</group>
<item android:title="@string/navigation_drawer_group_title"
android:id="@+id/other_labels">
<menu>
<item android:id="@+id/nav_myAccountSettings"
android:icon="@drawable/ic_settings"
android:title="My Account" />
<item android:id="@+id/nav_application_settings"
android:icon="@drawable/ic_action_settings"
android:title="Application Settings" />
<item android:id="@+id/comparison"
android:icon="@drawable/ic_swap_horiz"
android:title="Compare"/>
<item android:id="@+id/nav_help_and_feedback"
android:icon="@drawable/ic_live_help"
android:title="Help and Feedback" />
<item android:id="@+id/nav_logout"
android:icon="@drawable/ic_action_exit"
android:title="Sign Out" />
</menu>
</item>
以编程方式添加选项 -
Menu menu = mNavigationView.getMenu();
menu.add(0, Menu.FIRST, Menu.FIRST, "Players")
.setIcon(R.drawable.ic_people);
此选项最后添加。如何在第三个位置添加选项,即在“应用程序设置”
下面答案 0 :(得分:1)
试试这个:
Menu.THIRD=3;
Menu menu = mNavigationView.getMenu();
menu.add(0, Menu.THIRD, 2, "Players")
.setIcon(R.drawable.music_audio);
答案 1 :(得分:0)
你可以使用。
<form [formGroup]="segmentForm" (ngSubmit)="onSubmit()">
<select (change)="segmentOneSelected()" formControlName="segmentOne" class="form-control segment-1">
<option *ngFor="let segment of segmentsForAnalysis" [value]="segment.value" >{{segment.name}}</option>
</select>
</form>