8

नहीं खोलता है मैं इस एनएवी दराज जो बिल्कुल ठीक काम कर रहा था की है। मेरे कोड को दोबारा प्रतिक्रिया देते हुए मैंने गतिविधियों में सभी onOptionsItemSelecteds हटा दिए और सभी गतिविधियों को मूल गतिविधि से प्राप्त किया जो AppComplatActivity और लागू करता है सभी आवश्यक विधियों को लागू करता है। हैमबर्गर आइकन पर इस पर क्लिक करने के बाद किसी भी अधिक है, भले ही मैं syncstate है काम नहीं करता है() और हर चीज।क्लिक करने हैमबर्गर आइकन मार्गदर्शक ड्रॉवर

कोई सुराग क्यों यह काम नहीं कर रहा?

गतिविधियों में से एक:

public class MainActivity extends BaseActivity implements SearchFilterFragment.OnFragmentInteractionListener { 

NavigationView navigationView; 
DrawerLayout drawerLayout; 

private Tracker mTracker; 

@Override 
protected void onResume() { 
    super.onResume(); 
    drawerLayout.openDrawer(GravityCompat.START); 
} 

@Override 
protected void onPostResume() { 
    super.onPostResume(); 
    mTracker.setScreenName("MainActivity" + "-----"); 
    mTracker.send(new HitBuilders.ScreenViewBuilder().build()); 
} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL); 
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
    drawerLayout.openDrawer(GravityCompat.START); 
    navigationView = (NavigationView) findViewById(R.id.navigation_view_primary); 
    navigationView.setNavigationItemSelectedListener(new NavigationDrawerListener(this)); 
    setupToolbar(); 
    Haftdong application = (Haftdong) getApplication(); 
    mTracker = application.getDefaultTracker(); 
} 

private void setupToolbar() { 
    // Show menu icon 
    final ActionBar actionBar = getSupportActionBar(); 
    actionBar.setDisplayHomeAsUpEnabled(true);// will make the icon clickable and add the < at the left of the icon. 
    DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
    mDrawerLayout.setDrawerListener(mDrawerToggle); 
    mDrawerToggle.syncState();//for hamburger icon 
} 

@Override 
public void onFragmentInteraction(Uri uri) { 
} 

}

BaseActivity:

public class BaseActivity extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_base, 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); 
} 

}

उत्तर

18

आप उपयोग कर रहे हैं ActionBarDrawerToggle के लिए चार पैरामीटर निर्माता, जिसका अर्थ है आप को खोलने के लिए/दराज बंद क्रम में टॉगल के MainActivity के onOptionsItemSelected() ओवरराइड में onOptionsItemSelected() विधि कॉल करना होगा।

उदाहरण के लिए

:

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    if(mDrawerToggle.onOptionsItemSelected(item)) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 
+1

धन्यवाद एक बहुत :) – Tina

संबंधित मुद्दे