2017-02-25 4 views
1

私はAndroidがかなり新しいです。だから、このシリーの問題で私を助けてください 私は2つのナビゲーションバーを取得しています。私は両方の合併と1つのナビゲーションバー内のすべての要素を取得したいenter image description here これは、これは私のmanifest.xml1つのナビゲーションバーを取り除き、アンドロイドでそれらを1つにマージするにはどうすればいいですか?

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="info.androidhive.navigationdrawer"> 

     <uses-permission android:name="android.permission.INTERNET" /> 

     <application 
      android:allowBackup="true" 
      android:icon="@mipmap/ic_launcher" 
      android:label="@string/app_name" 
      android:supportsRtl="true" 
      android:theme="@style/AppTheme"> 
      <activity 
       android:name=".activity.LoginActivity" 
       > 
       <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 

        <category android:name="android.intent.category.LAUNCHER" /> 
       </intent-filter> 
      </activity> 
      <activity 
       android:name=".activity.AboutUsActivity" 
       android:label="@string/activity_title_about_us" /> 
      <activity 
       android:name=".activity.PrivacyPolicyActivity" 
       android:label="@string/activity_title_privacy_policy" /> 
      <activity android:name=".activity.MainActivity" 
       android:label="Main" 
       > 

      </activity> 
     </application> 

    </manifest> 

である私のMainActivity

ですこれは私の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> 

これは私のapp_bar_main.xmlです

Th私nav_header_main.xml

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout   xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/view_container" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/nav_header_height" 
     android:gravity="bottom" 
     android:orientation="vertical" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

     <ImageView 
      android:id="@+id/img_header_bg" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="fitXY" 
      android:src="@mipmap/ic_launcher" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:orientation="vertical" 
      android:padding="@dimen/activity_horizontal_margin"> 

      <ImageView 
       android:id="@+id/img_profile" 
       android:layout_width="@dimen/profile_width" 
       android:layout_height="@dimen/profile_height" 
       android:paddingTop="@dimen/nav_header_vertical_spacing" 
       app:srcCompat="@android:drawable/sym_def_app_icon" /> 

      <TextView 
       android:id="@+id/name" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:paddingTop="@dimen/nav_header_vertical_spacing" 
         android:textAppearance="@style/TextAppearance.AppCompat.Body1"  /> 

      <TextView 
       android:id="@+id/website" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

     </LinearLayout> 


    </RelativeLayout> 

ですこれはhttp://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

から取られた私のactivity_main_drawer.xml

<?xml version="1.0" encoding="utf-8"?> 
    <menu xmlns:android="http://schemas.android.com/apk/res/android"> 

     <group android:checkableBehavior="single"> 
      <item 
       android:id="@+id/nav_home" 
       android:icon="@drawable/ic_home_black_24dp" 
       android:title="@string/nav_home" /> 
      <item 
       android:id="@+id/nav_photos" 
       android:icon="@drawable/ic_photo_library_black_24dp" 
       android:title="@string/nav_photos" /> 
      <item 
       android:id="@+id/nav_movies" 
       android:icon="@drawable/ic_local_movies_black_24dp" 
       android:title="@string/nav_movies" /> 

      <item 
       android:id="@+id/nav_notifications" 
       android:icon="@drawable/ic_notifications_black_24dp" 
       android:title="@string/nav_notifications" /> 

      <item 
       android:id="@+id/nav_settings" 
       android:icon="@drawable/ic_settings_black_24dp" 
       android:title="@string/nav_settings" /> 
     </group> 

     <item android:title="Other"> 
      <menu> 
       <item 
        android:id="@+id/nav_about_us" 
        android:title="@string/nav_about_us" /> 
       <item 
        android:id="@+id/nav_privacy_policy" 
        android:title="@string/privacy_policy" /> 
      </menu> 
     </item> 

    </menu> 

オリジナルコードです事前にありがとうございます! :)

編集 これは、あなたが簡単なステップでそれを行うことができ、私のMainActivity.java

package info.androidhive.navigationdrawer.activity; 

    import android.content.Intent; 
    import android.content.SharedPreferences; 
    import android.os.Bundle; 
    import android.os.Handler; 
    import android.support.design.widget.FloatingActionButton; 
    import android.support.design.widget.NavigationView; 
    import android.support.design.widget.Snackbar; 
    import android.support.v4.app.Fragment; 
    import android.support.v4.app.FragmentTransaction; 
    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.view.View; 
    import android.widget.ImageView; 
    import android.widget.TextView; 
    import android.widget.Toast; 

    import com.bumptech.glide.Glide; 
    import com.bumptech.glide.load.engine.DiskCacheStrategy; 

    import info.androidhive.navigationdrawer.R; 
    import info.androidhive.navigationdrawer.fragment.HomeFragment; 
    import info.androidhive.navigationdrawer.fragment.MoviesFragment; 
    import info.androidhive.navigationdrawer.fragment.NotificationsFragment; 
    import info.androidhive.navigationdrawer.fragment.PhotosFragment; 
    import info.androidhive.navigationdrawer.fragment.SettingsFragment; 
    import info.androidhive.navigationdrawer.helper.SessionManager; 
    import info.androidhive.navigationdrawer.other.CircleTransform; 

    public class MainActivity extends AppCompatActivity { 

     private NavigationView navigationView; 
     private DrawerLayout drawer; 
     private View navHeader; 
     private ImageView imgNavHeaderBg, imgProfile; 
     private TextView txtName, txtWebsite; 
     private Toolbar toolbar; 
     private FloatingActionButton fab; 

     // urls to load navigation header background image 
     // and profile image 
     private static final String urlNavHeaderBg =   "http://api.androidhive.info/images/nav-menu-header-bg.jpg"; 
     private static final String urlProfileImg =   "https://lh3.googleusercontent.com/eCtE_G34M9ygdkmOpYvCag1vBARCmZwnVS6rS5t4JLzJ6  QgQSBquM0nuTsCpLhYbKljoyS-txg"; 
     private SessionManager session; 
     // index to identify current nav menu item 
     public static int navItemIndex = 0; 

     // tags used to attach the fragments 
     private static final String TAG_HOME = "home"; 
     private static final String TAG_PHOTOS = "photos"; 
     private static final String TAG_MOVIES = "movies"; 
     private static final String TAG_NOTIFICATIONS = "notifications"; 
     private static final String TAG_SETTINGS = "settings"; 
     public static String CURRENT_TAG = TAG_HOME; 

     // toolbar titles respected to selected nav menu item 
     private String[] activityTitles; 

     // flag to load home fragment when user presses back key 
     private boolean shouldLoadHomeFragOnBackPress = true; 
     private Handler mHandler; 


     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 
      toolbar = (Toolbar) findViewById(R.id.toolbar); 
      // setSupportActionBar(toolbar); 
      session = new SessionManager(getApplicationContext()); 
      mHandler = new Handler(); 

      drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
      navigationView = (NavigationView) findViewById(R.id.nav_view); 
      fab = (FloatingActionButton) findViewById(R.id.fab); 

      // Navigation view header 
      navHeader = navigationView.getHeaderView(0); 
      txtName = (TextView) navHeader.findViewById(R.id.name); 
      txtWebsite = (TextView) navHeader.findViewById(R.id.website); 
      imgNavHeaderBg = (ImageView)   navHeader.findViewById(R.id.img_header_bg); 
      imgProfile = (ImageView)   navHeader.findViewById(R.id.img_profile); 

      // load toolbar titles from string resources 
      activityTitles =   getResources().getStringArray(R.array.nav_item_activity_titles); 

      fab.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        Snackbar.make(view, "Replace with your own action",   Snackbar.LENGTH_LONG) 
          .setAction("Action", null).show(); 
       } 
      }); 

      // load nav menu header data 
      loadNavHeader(); 

      // initializing navigation menu 
      setUpNavigationView(); 

      if (savedInstanceState == null) { 
       navItemIndex = 0; 
       CURRENT_TAG = TAG_HOME; 
       loadHomeFragment(); 
      } 
       if (!session.isLoggedIn()) { 
       logoutUser(); 
      } 
      SharedPreferences prefs = getSharedPreferences("LoginActivity", 
        MODE_PRIVATE); String string =   prefs.getString("output", 
        "nothing to display"); 
      } 

     /*** 
     * Load navigation menu header information 
     * like background image, profile image 
     * name, website, notifications action view (dot) 
      */ 
     private void loadNavHeader() { 
      // name, website 
      txtName.setText("Ravi Tamada"); 
      txtWebsite.setText("www.androidhive.info"); 

      // loading header background image 
      Glide.with(this).load(urlNavHeaderBg) 
        .crossFade() 
        .diskCacheStrategy(DiskCacheStrategy.ALL) 
        .into(imgNavHeaderBg); 

       // Loading profile image 
      Glide.with(this).load(urlProfileImg) 
         .crossFade() 
         .thumbnail(0.5f) 
        .bitmapTransform(new CircleTransform(this)) 
        .diskCacheStrategy(DiskCacheStrategy.ALL) 
        .into(imgProfile); 

      // showing dot next to notifications label 
      navigationView.getMenu().getItem(3).setActionView(R.layout.menu_dot); 
     } 

     /*** 
      * Returns respected fragment that user 
      * selected from navigation menu 
      */ 
     private void loadHomeFragment() { 
      // selecting appropriate nav menu item 
      selectNavMenu(); 

      // set toolbar title 
      setToolbarTitle(); 

      // if user select the current navigation menu again, don't do   anything 
      // just close the navigation drawer 
      if (getSupportFragmentManager().findFragmentByTag(CURRENT_TAG)   != null) { 
       drawer.closeDrawers(); 

       // show or hide the fab button 
       toggleFab(); 
       return; 
      } 

      // Sometimes, when fragment has huge data, screen seems hanging 
      // when switching between navigation menus 
      // So using runnable, the fragment is loaded with cross fade   effect 
      // This effect can be seen in GMail app 
      Runnable mPendingRunnable = new Runnable() { 
       @Override 
       public void run() { 
        // update the main content by replacing fragments 
        Fragment fragment = getHomeFragment(); 
        FragmentTransaction fragmentTransaction =   getSupportFragmentManager().beginTransaction(); 
        fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, 
          android.R.anim.fade_out); 
        fragmentTransaction.replace(R.id.frame, fragment,   CURRENT_TAG); 
        fragmentTransaction.commitAllowingStateLoss(); 
       } 
      }; 

      // If mPendingRunnable is not null, then add to the message queue 
      if (mPendingRunnable != null) { 
       mHandler.post(mPendingRunnable); 
      } 

      // show or hide the fab button 
      toggleFab(); 

      //Closing drawer on item click 
      drawer.closeDrawers(); 

      // refresh toolbar menu 
      invalidateOptionsMenu(); 
     } 

     private Fragment getHomeFragment() { 
      switch (navItemIndex) { 
       case 0: 
        // home 
        HomeFragment homeFragment = new HomeFragment(); 
        return homeFragment; 
       case 1: 
        // photos 
        PhotosFragment photosFragment = new PhotosFragment(); 
        return photosFragment; 
       case 2: 
        // movies fragment 
        MoviesFragment moviesFragment = new MoviesFragment(); 
        return moviesFragment; 
       case 3: 
        // notifications fragment 
        NotificationsFragment notificationsFragment = new   NotificationsFragment(); 
        return notificationsFragment; 

       case 4: 
        // settings fragment 
        SettingsFragment settingsFragment = new   SettingsFragment(); 
        return settingsFragment; 
       default: 
        return new HomeFragment(); 
      } 
     } 

     private void setToolbarTitle() { 
      getSupportActionBar().setTitle(activityTitles[navItemIndex]); 
     } 

     private void selectNavMenu() { 
      navigationView.getMenu().getItem(navItemIndex).setChecked(true); 
     } 

     private void setUpNavigationView() { 
      //Setting Navigation View Item Selected Listener to handle the   item click of the navigation menu 
      navigationView.setNavigationItemSelectedListener(new   NavigationView.OnNavigationItemSelectedListener() { 

       // This method will trigger on item Click of navigation menu 
       @Override 
       public boolean onNavigationItemSelected(MenuItem menuItem) { 

         //Check to see which item was being clicked and perform appropriate action 
        switch (menuItem.getItemId()) { 
         //Replacing the main content with ContentFragment Which is our Inbox View; 
         case R.id.home: 
          navItemIndex = 0; 
          CURRENT_TAG = TAG_HOME; 
          break; 
         case R.id.nav_photos: 
          navItemIndex = 1; 
          CURRENT_TAG = TAG_PHOTOS; 
          break; 
         case R.id.nav_movies: 
          navItemIndex = 2; 
          CURRENT_TAG = TAG_MOVIES; 
          break; 
         case R.id.nav_notifications: 
          navItemIndex = 3; 
          CURRENT_TAG = TAG_NOTIFICATIONS; 
          break; 
         case R.id.nav_settings: 
          navItemIndex = 4; 
          CURRENT_TAG = TAG_SETTINGS; 
          break; 
         case R.id.nav_about_us: 
          // launch new intent instead of loading fragment 
          startActivity(new Intent(MainActivity.this,   AboutUsActivity.class)); 
          drawer.closeDrawers(); 
          return true; 
         case R.id.nav_privacy_policy: 
          // launch new intent instead of loading fragment 
          startActivity(new Intent(MainActivity.this,   PrivacyPolicyActivity.class)); 
          drawer.closeDrawers(); 
          return true; 
         default: 
          navItemIndex = 0; 
        } 

        //Checking if the item is in checked state or not, if not make it in checked state 
        if (menuItem.isChecked()) { 
         menuItem.setChecked(false); 
        } else { 
         menuItem.setChecked(true); 
        } 
        menuItem.setChecked(true); 

        loadHomeFragment(); 

        return true; 
       } 
      }); 


      ActionBarDrawerToggle actionBarDrawerToggle = new   ActionBarDrawerToggle(this, drawer, toolbar, R.string.openDrawer,   R.string.closeDrawer) { 

       @Override 
       public void onDrawerClosed(View drawerView) { 
        // Code here will be triggered once the drawer closes as   we dont want anything to happen so we leave this blank 
        super.onDrawerClosed(drawerView); 
       } 

       @Override 
       public void onDrawerOpened(View drawerView) { 
        // Code here will be triggered once the drawer open as   we dont want anything to happen so we leave this blank 
        super.onDrawerOpened(drawerView); 
       } 
      }; 

      //Setting the actionbarToggle to drawer layout 
      drawer.setDrawerListener(actionBarDrawerToggle); 

      //calling sync state is necessary or else your hamburger icon   wont show up 
      actionBarDrawerToggle.syncState(); 
     } 

     @Override 
     public void onBackPressed() { 
      if (drawer.isDrawerOpen(GravityCompat.START)) { 
       drawer.closeDrawers(); 
       return; 
      } 

      // This code loads home fragment when back key is pressed 
      // when user is in other fragment than home 
      if (shouldLoadHomeFragOnBackPress) { 
       // checking if user is on other navigation menu 
       // rather than home 
       if (navItemIndex != 0) { 
        navItemIndex = 0; 
        CURRENT_TAG = TAG_HOME; 
        loadHomeFragment(); 
        return; 
       } 
      } 

      super.onBackPressed(); 
     } 

     @Override 
     public boolean onCreateOptionsMenu(Menu menu) { 
      // Inflate the menu; this adds items to the action bar if it is   present. 

      // show menu only when home fragment is selected 
      if (navItemIndex == 0) { 
       getMenuInflater().inflate(R.menu.main, menu); 
      } 

      // when fragment is notifications, load the menu created for   notifications 
      if (navItemIndex == 3) { 
       getMenuInflater().inflate(R.menu.notifications, menu); 
      } 
      return true; 
     } 

     @Override 
     public boolean onOptionsItemSelected(MenuItem item) { 
      // Handle action bar item clicks here. The action bar will 
      // automatically handle clicks on the Home/Up button, so long 
      // as you specify a parent activity in AndroidManifest.xml. 
      int id = item.getItemId(); 

      //noinspection SimplifiableIfStatement 
      if (id == R.id.action_logout) { 
       logoutUser(); 
      } 

      // user is in notifications fragment 
      // and selected 'Mark all as Read' 
      if (id == R.id.action_mark_all_read) { 
       Toast.makeText(getApplicationContext(), "All notifications   marked as read!", Toast.LENGTH_LONG).show(); 
      } 

      // user is in notifications fragment 
      // and selected 'Clear All' 
      if (id == R.id.action_clear_notifications) { 
       Toast.makeText(getApplicationContext(), "Clear all   notifications!", Toast.LENGTH_LONG).show(); 
      } 

      return super.onOptionsItemSelected(item); 
     } 

     // show or hide the fab 
     private void toggleFab() { 
      if (navItemIndex == 0) 
       fab.show(); 
      else 
       fab.hide(); 
     } 
     private void logoutUser() { 
      session.setLogin(false); 



      // Launching the login activity 
      Intent intent = new Intent(getApplicationContext(),   LoginActivity.class); 
      startActivity(intent); 
      finish(); 
     } 

    } 
+0

Javaコードを表示できますか?上記のコードは2つのナビゲーションドロワーを表示しません –

+0

@jinsLukose私はapp_bar_main.xmlからandroid.support.v7.widget.Toolbarを取り出しました。しかし、今、Hambugerのアイコンがそのツールバーで消えてしまった。 – yash

答えて

0

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> 

app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="videoeditor.myapplication.MainActivity"><android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

<FrameLayout 
    android:id="@+id/frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"></FrameLayout> 

<include layout="@layout/content_main" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    app:srcCompat="@android:drawable/ic_dialog_email" /> 

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

content_main.xml

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 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:layout_width="match_parent" 
android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="videoeditor.myapplication.MainActivity" 
tools:showIn="@layout/app_bar_main"> 


<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World!" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" /></RelativeLayout> 

javaの

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); 

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
    fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
        .setAction("Action", null).show(); 
     } 
    }); 

    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); 
} 

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

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

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

    if (id == R.id.nav_camera) { 
     // Handle the camera action 
    } else if (id == R.id.nav_gallery) { 

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

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

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

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

    } 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    drawer.closeDrawer(GravityCompat.START); 
    return true; 
} 

}

enter image description here

そうのstyles.xml

<resources> 

をこのコードを入れない場合は、ナビゲーションバー

としてこれを意味します

<item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

<style name="AppThemee.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style></resources> 
+0

これは私のために完全に動作します –

+0

いいえ、まだ2つのナビゲーションバーを表示します。とにかく、ありがとうございました。 – yash

+0

私はあなたのJavaファイルを表示することができます –

0

です。レイアウトからandroid.support.design.widget.AppBarLayoutを削除しないでください。代わりに、app:elevation="0dp"という属性を追加してください。あなたの最終的なレイアウトは次のようになります。

<android.support.design.widget.AppBarLayout 
      android:id="@+id/appBarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:elevation="0dp"> 
      ... 
</android.support.design.widget.AppBarLayout> 
関連する問題