[英]Navigation component drawer button click not working
我在點擊最上面鏈接的按鈕時遇到問題,它不起作用,即使所有配置的設置方式都與其他配置相同。 任何人都可以看看,如果他們能找出問題所在?
我在導航抽屜R.id.nav_home
中有一個菜單鏈接,它不響應按鈕單擊。
我已將所有片段設置為頂級導航,以在各處顯示三明治圖標。 除nav_home
外,所有鏈接都有效,這也是我的startDestination
。
主要活動
{
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_search_employee, R.id.nav_goods_issue, R.id.nav_issue_point,
R.id.nav_goods_incoming, R.id.nav_brokenInitialFragment, R.id.nav_goodsBroken,
R.id.nav_goodsBrokenPerson, R.id.nav_billing, R.id.nav_log_out, R.id.nav_sync,
R.id.nav_issue_point_selection, R.id.nav_orders_completion, R.id.nav_orders_log_detail)
.setOpenableLayout(drawer)
.build();
}
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}
菜單
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<item
android:id="@+id/nav_home"
android:title="@string/overview_team_leader" />
<item
android:id="@+id/nav_goods_issue"
android:title="@string/output" />
<item
android:id="@+id/nav_issue_point"
android:title="@string/delivery_and_return" />
.....
導航圖
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/mobile_navigation"
app:startDestination="@+id/nav_home">
<fragment
android:id="@+id/nav_home"
android:name="de.eyescontact.ui.home.HomeFragment"
android:label="@string/overview_team_leader"
tools:layout="@layout/fragment_main" >
<action
android:id="@+id/action_nav_home_to_nav_registration"
app:destination="@id/nav_search_employee" />
<action
android:id="@+id/action_nav_home_to_nav_issue_article"
app:destination="@id/nav_issue_point" />
<action
android:id="@+id/action_nav_home_to_nav_return_article"
app:destination="@id/nav_goods_incoming" />
<action
android:id="@+id/action_nav_home_to_nav_issue_stock"
app:destination="@id/nav_goods_issue" />
<action
android:id="@+id/action_nav_home_to_nav_billing"
app:destination="@id/nav_billing" />
</fragment>
<!-- check in and inner fragment -->
<fragment
android:id="@+id/nav_search_employee"
android:name="de.eyescontact.ui.search.SearchFragment"
android:label="@string/all_search"
tools:layout="@layout/fragment_main"/>
....
導航圖中設置的主頁片段 ID ( nav_home
) 與抽屜菜單 ( nav_home_fragment
) 中設置的 ID 不匹配。 它們必須相同才能使導航正常工作。
如果 MenuItem 的 id 與目的地的 id 匹配,則 NavController 可以導航到該目的地。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.