0

こんにちは、ナビゲーション ビューを使用する場合、アプリ バーの右側に actionbardrawertoggle が必要です。

まず、メインのナビゲーション ビュー ->

<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="end">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

そして、ツールバー(またはアプリバー)の引き出しトグルをスワイプまたはクリックした場合、右側にこれが必要です。ただし、左側にあるため、引き出しのトグルは右側に表示されません。ボタンをクリックすると、この例外が発生します

java.lang.IllegalArgumentException: No drawer view found with gravity LEFT

この例外は当然、私のレイアウトが右側/端側にあるためです。それで、私の質問は、このボタンを右側に配置するにはどうすればよいですか? または、右ボタンでこの例外を解決するにはどうすればよいですか?

これが私のコードです:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close){

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu();
            syncState();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            invalidateOptionsMenu();
            syncState();
        }
    };
    drawer.setDrawerListener(toggle);
    toggle.setDrawerIndicatorEnabled(true);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    //add this line to display menu1 when the activity is loaded
    int firstMenu = R.id.nav_menu1;
    displaySelectedScreen(firstMenu);
    navigationView.setCheckedItem(firstMenu);
}

好奇心は、右から左へのスワイプが機能し、ナビゲーションビューが表示されていることです:)(しかし、ボタンは機能しません)

手伝って頂けますか ?:)

(下手な英語でごめんなさい!)

4

0 に答える 0