导航抽屉RTL朗

时间:2016-09-13 07:54:01

标签: android navigation-drawer

我在我的一个应用程序活动中使用导航抽屉它从左到右打开我如何将其从右向左和图标方向更改 我尝试layout_gravity:对;但是在运行应用程序时强制关闭 我没有从其他问题得到答案 应用程序最低SDK设置为15

这里是activity_main.XML

<?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"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
     >

    >

    <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="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

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

这是主要活动

package ir.diamonddesign.tajrobi96;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
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.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        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);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        navigationView.setItemIconTintList(null);


    }


    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }


    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.homeitem) {
            Intent mIntent = new Intent(this, MainActivity.class);
            startActivity(mIntent);

        } else if (id == R.id.questionitem) {
            Intent mIntent = new Intent(this, Questionsactivity.class);
            startActivity(mIntent);
        } else if (id == R.id.answeritem) {

        } else if (id == R.id.eduitem) {

        } else if (id == R.id.sourceitem) {

        } else if (id == R.id.changeitem) {

        } else if (id == R.id.videositem) {

        } else if (id == R.id.newsitem) {

        } else if (id == R.id.shareitem) {

            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            String shareBody = "اینو ببین : https://cafebazaar.ir/app/ir.tik.tik/?l=fa";
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "موضوع پیام");
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
            startActivity(Intent.createChooser(sharingIntent, "از طریق"));

        } else if (id == R.id.contactitem) {



            String[] TO = {"tajrobi@tinytree.ml"};

            Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO,Uri.fromParts("mailto", "", null));
            emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "موضوع پیام");
            emailIntent.putExtra(Intent.EXTRA_TEXT,"سلام از اپیکیشن کنکور تماس میگیرم....");
            startActivity(emailIntent);




        }



        else if (id == R.id.exititem) {
finish();
        }
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

1 个答案:

答案 0 :(得分:0)

更改应用程序的区域设置时,它将自动更改为RTL。