Как поставить переключатель меню на правой стороне панели действий Android Studio - PullRequest
0 голосов
/ 19 ноября 2018

У меня есть ящик для навигаторов, который отлично работает, но значок ящика находится на левой стороне панели действий, и я хочу, чтобы он был на правой стороне.

Я посмотрел еще один вопрос, опубликованный здесь, но не совсем понял, как применить его к моей проблеме

Значок переключения ящика навигации Android вправо

Кто-нибудь может помочь? Я прочитал форумы и другие вопросы, я не хочу, чтобы перевернуть макет

Вот план действий

    <?xml version="1.0" encoding="utf-8"?>
    <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"
    tools:context=".MainMenu"
    android:orientation="vertical"
    android:background="@color/background"
    android:gravity="center">

    <?xml version="1.0" encoding="utf-8"?>
    <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"
    tools:context=".MainMenu"
    android:orientation="vertical"
    android:background="@color/background"
    android:gravity="center">



    <LinearLayout
        android:clipToPadding="false"
        android:gravity="top"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.CardView
            android:id="@+id/manageStudents_card"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_margin="10dp"
            android:clickable="true"
            android:foreground="?android:attr/selectableItemBackground">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:layout_gravity="center_vertical"
                    android:background="@drawable/database"
                    android:padding="10dp"
                    android:src="@drawable/ic_students_cap" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"

                    android:layout_gravity="center"
                    android:layout_marginLeft="20dp"
                    android:text="MANAGE STUDENTS"
                    android:textSize="20dp"
                    android:textStyle="bold" />


            </LinearLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/manageModule_card"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_margin="10dp"
            android:clickable="true"
            android:foreground="?android:attr/selectableItemBackground">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:layout_gravity="center_vertical"
                    android:background="@drawable/manager"
                    android:padding="10dp"
                    android:src="@drawable/ic_manager_gears" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"

                    android:layout_gravity="center"
                    android:layout_marginLeft="20dp"
                    android:text="MANAGE MODULES"
                    android:textSize="20dp"
                    android:textStyle="bold" />


            </LinearLayout>
        </android.support.v7.widget.CardView>

        <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>


    </LinearLayout>

    <android.support.design.widget.NavigationView
        app:headerLayout="@layout/header"
        android:id="@+id/navList"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:itemTextColor="@color/background"
        app:itemIconTint="@color/background"
        android:background="@color/menuDrawer"
        app:menu="@menu/menu_main">

    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

Вот класс Java

    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.support.annotation.NonNull;
    import android.support.design.widget.NavigationView;
    import android.support.v4.view.GravityCompat;
    import android.support.v4.widget.DrawerLayout;
    import android.support.v7.app.ActionBarDrawerToggle;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.CardView;
    import android.util.Log;
    import android.view.MenuItem;
    import android.view.View;

    public class ManagerMenu extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
    private static final String TAG = "mMenu";
    private DrawerLayout mDrawerLayout;
    private ActionBarDrawerToggle mDrawerToggle;
    public static final String PREFS_NAME = "SigninPrefs";

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

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        NavigationView navigationView = findViewById(R.id.navList);
        navigationView.setNavigationItemSelectedListener(this);

        mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, R.string.drawer_open, R.string.drawer_close);
        mDrawerLayout.addDrawerListener(mDrawerToggle);
        mDrawerToggle.syncState();
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        CardView manage_student=findViewById(R.id.manageStudents_card);
        manage_student.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG,"open activity");
                Intent intent=new Intent(getApplicationContext(),ManageStudent.class);
                startActivity(intent);
            }
        });

        CardView manage_module=findViewById(R.id.manageModule_card);
        manage_module.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getApplicationContext(),StudentModule.class);
                startActivity(intent);
            }
        });

    }

    //Handles Item clicks in navigation drawer
    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()){
            case R.id.home:
                Intent MainMenu=new Intent(getApplicationContext(), wintec_cfit_managers.wintecdpm.MainMenu.class);
                finish();
                startActivity(MainMenu);
                break;
            case R.id.students_cap:
                Intent ManageStudent=new Intent(getApplicationContext(),ModuleDescription.class);
                startActivity(ManageStudent);
                break;
            case R.id.manage_module:
                Intent ManageModule=new Intent(getApplicationContext(),ModuleDescription.class);
                startActivity(ManageModule);
                break;
            case R.id.about:
                Intent About=new Intent(getApplicationContext(),AboutUs.class);
                startActivity(About);
                break;
            case R.id.signout:
                if (item.getItemId() == R.id.signout) {
                    //Clears sign in for shared preferences
                    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.clear();
                    editor.commit();
                    finish();
                }
                return super.onOptionsItemSelected(item);
        }

        mDrawerLayout.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();

        if(mDrawerToggle.onOptionsItemSelected(item)){
            return (true);

        }

        if (id == R.id.home) {

            Intent intent = new Intent(this,MainMenu.class);
            this.startActivity(intent);
            return true;
        }

        if (id == R.id.students_cap) {

            Intent intent = new Intent(this,ManageStudent.class);
            this.startActivity(intent);
            return true;
        }

        if (id == R.id.manage_module) {

            Intent intent = new Intent(this,ManageModule.class);
            this.startActivity(intent);
            return true;
        }

        if (id == R.id.about) {

            Intent intent = new Intent(this,AboutUs.class);
            this.startActivity(intent);
            return true;
        }
            if (item.getItemId() == R.id.signout) {

            Intent intent = new Intent(this,MainMenu.class);
            this.startActivity(intent);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }



}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...