2016-09-12 6 views
-1

Ich habe eine Navigationsschubladeanwendung, die den Überlaufknopf nicht anzeigt. Ich habe überprüft und mein Gerät hat keine Menü-Taste, so sollte es erscheinen, aber ich bin mir nicht sicher, warum es nicht erscheint. Einige meiner Code untenKein Überlaufknopf

Haupt Layout-

<?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" 
     android:background="@color/colorPrimary"> 

     <include 
      layout="@layout/app_bar_brgo" 
      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_brgo" 
      app:menu="@menu/activity_brgo_drawer" 
      app:itemTextColor="@color/colorPrimaryDark" 
      app:itemBackground="@color/colorPrimary" 
      android:background="@color/colorPrimary"/> 
    </android.support.v4.widget.DrawerLayout> 

App Bar

<?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" 
    android:fitsSystemWindows="true" 
    tools:context="com.tble.brgo.BRGO"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:theme="@style/AppTheme" 
> 

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

    </android.support.design.widget.AppBarLayout> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@color/colorAccent"/> 

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

</FrameLayout> 
    </LinearLayout> 

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

Menü

<?xml version="1.0" encoding="utf-8"?> 
<menu 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" 
    tools:context="com.tble.brgo.BRGO"> 
    <item 
     android:id="@+id/S14273" 
     android:orderInCategory="100" 
     android:title="High School" 
     app:showAsAction="never" /> 
    <item 
     android:id="@+id/S14276" 
     android:orderInCategory="100" 
     android:title="Middle School" 
     app:showAsAction="never" /> 
    <item 
     android:id="@+id/S14274" 
     android:orderInCategory="100" 
     android:title="Hillside" 
     app:showAsAction="never" /> 
    <item 
     android:id="@+id/S14271" 
     android:orderInCategory="100" 
     android:title="Eisenhower" 
     app:showAsAction="never" /> 
    <item 
     android:id="@+id/S14278" 
     android:orderInCategory="100" 
     android:title="Van Holten" 
     app:showAsAction="never" /> 
    <item 
     android:id="@+id/S14277" 
     android:orderInCategory="100" 
     android:title="Milltown" 
     app:showAsAction="never" /> 
    <item 
     android:id="@+id/S14275" 
     android:orderInCategory="100" 
     android:title="J.F.K. Primary" 
     app:showAsAction="never" /> 
    <item 
     android:id="@+id/S14272" 
     android:orderInCategory="100" 
     android:title="Hamilton" 
     app:showAsAction="never" /> 
    <item 
     android:id="@+id/S14269" 
     android:orderInCategory="100" 
     android:title="Crim Primary" 
     app:showAsAction="never" /> 
    <item 
     android:id="@+id/S14268" 
     android:orderInCategory="100" 
     android:title="Bradely Gardens" 
     app:showAsAction="never" /> 
    <item 
     android:id="@+id/S14264" 
     android:orderInCategory="100" 
     android:title="Adamsville" 
     app:showAsAction="never" /> 

</menu> 

Haupt Java-Datei

package com.tble.brgo; 

import android.content.Context; 
import android.content.SharedPreferences; 
import android.os.Bundle; 
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.support.v4.app.Fragment; 
import android.support.v4.app.FragmentTransaction; 
import android.support.v4.app.FragmentManager; 
import android.view.LayoutInflater; 
import android.view.View; 
import layout.Calendar; 
import layout.News; 
import layout.StudentID; 
import layout.Temp; 
import layout.Websites; 
import layout.About; 

public class BRGO extends AppCompatActivity 
     implements NavigationView.OnNavigationItemSelectedListener { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_brgo); 
     News initial = new News(); 
     FragmentTransaction transfer = getSupportFragmentManager().beginTransaction(); 
     transfer.replace(R.id.fragmentcontainer, initial).commit(); 
     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.addDrawerListener(toggle); 
     toggle.syncState(); 
     NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
     navigationView.setNavigationItemSelectedListener(this); 
     navigationView.setItemTextAppearance(R.style.itemFont); 
    } 

    @Override 
    public void onBackPressed() { 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     if (drawer.isDrawerOpen(GravityCompat.START)) { 
      drawer.closeDrawer(GravityCompat.START); 
     } else { 
      super.onBackPressed(); 
     } 
    } 
    public void takePic(View v) { 
     FragmentManager fm = getSupportFragmentManager(); 
     StudentID temp = (StudentID) fm.findFragmentById(R.id.fragmentcontainer); 
     temp.takePicture(); 
    } 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.brgo, 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(); 
     SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE); 
     SharedPreferences.Editor editor = sharedPref.edit(); 
     //noinspection SimplifiableIfStatement 
     if (id == R.id.S14273) { 
     editor.putInt("School", 14273); 
      editor.commit(); 
      return true; 
     } 
     else if(id == R.id.S14276){ 
      editor.putInt("School", 14276); 
      editor.commit(); 
      return true; 
     } 
     else if(id == R.id.S14274){ 
      editor.putInt("School", 14274); 
      editor.commit(); 
      return true; 
     } 
     else if(id == R.id.S14271){ 
      editor.putInt("School", 14271); 
      editor.commit(); 
      return true; 
     } 
     else if(id == R.id.S14278){ 
      editor.putInt("School", 14278); 
      editor.commit(); 
      return true; 
     } 
     else if(id == R.id.S14277){ 
      editor.putInt("School", 14273); 
      editor.commit(); 
      return true; 
     } 
     else if(id == R.id.S14275){ 
      editor.putInt("School", 14275); 
      editor.commit(); 
      return true; 
     } 
     else if(id == R.id.S14272){ 
      editor.putInt("School", 14272); 
      editor.commit(); 
      return true; 
     } 
     else if(id == R.id.S14269){ 
      editor.putInt("School", 14269); 
      editor.commit(); 
      return true; 
     } 
     else if(id == R.id.S14268){ 
      editor.putInt("School", 14268); 
      editor.commit(); 
      return true; 
     } 
     else if(id == R.id.S14264){ 
      editor.putInt("School", 14264); 
      editor.commit(); 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 

    @SuppressWarnings("StatementWithEmptyBody") 
    @Override 
    public boolean onNavigationItemSelected(MenuItem item) { 
     // Handle navigation view item clicks here. 
     int id = item.getItemId(); 
     Fragment fragment; 
     switch (id) { 
      case R.id.nav_News: 
       fragment = News.newInstance(); 
       break; 
      case R.id.nav_Calendar: 
       fragment = Calendar.newInstance(); 
       break; 
      case R.id.nav_Websites: 
       fragment = Websites.newInstance(); 
       break; 
      case R.id.nav_About: 
       fragment = About.newInstance(); 
       break; 
      default: 
       fragment = Temp.newInstance(); 
       break; 
     } 
     FragmentTransaction transfer = getSupportFragmentManager().beginTransaction(); 
     transfer.replace(R.id.fragmentcontainer,fragment).addToBackStack("tag").commit(); 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     drawer.closeDrawer(GravityCompat.START); 
     return true; 
    } 
} 
+0

orderInCategory = "100" in allen Menüpunkten. Durch diese Logik wird nur ein Menüpunkt angezeigt. Make orderInCategory = "100", "200", "300" ... für die Menüpunkte – suku

+1

Mögliches Duplikat der [Überlauf-Schaltfläche ist verschwunden] (http://stackoverflow.com/questions/39281317/overflow-button-has- verschwunden) –

+1

Bitte bearbeiten Sie Ihre Fragen, um auf die Titelseite zu gelangen. Repotieren Sie nicht –

Antwort

0

In onCreateOptionMenu Retun:

return super.onCreateOptionsMenu(menu); 

statt return true.

+0

Das hat keine Wirkung – Praveen

Verwandte Themen