java - After making actionbar smaller, navigation drawer toggle doesn't work -


i had action bar toggle worked, reason every time changed color of action bar, color of entire page changed. figured out because action bar taking entire screen. made fixes (moved action bar larger linear layout instead of keeping in drawer layout itself), since taking care of that, toggle no longer works, , related, when drag navigation drawer out, hangs second, , have pull there. in advance help.

mainactivity.java

package me.paxana.alerta;  import android.app.activity; import android.graphics.color; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmenttransaction; import android.support.v4.app.fragmentmanager; import android.support.v7.app.actionbar; import android.support.v7.app.actionbardrawertoggle; import android.app.fragment; import android.content.intent; import android.support.v4.widget.drawerlayout; import android.support.v7.app.actionbaractivity; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.menuinflater; import android.view.view; import android.widget.adapterview; import android.widget.listview; import android.support.v7.widget.toolbar; import com.parse.parseuser; import java.util.arraylist; import java.util.list; import butterknife.bind; import butterknife.butterknife; import me.paxana.alerta.adapter.slidingmenuadapter; import me.paxana.alerta.fragment.fragment1; import me.paxana.alerta.fragment.fragment2; import me.paxana.alerta.fragment.fragment3; import me.paxana.alerta.model.itemslidemenu;  public class mainactivity extends appcompatactivity {     public static final string tag = mainactivity.class.getsimplename();     private list<itemslidemenu> listsliding;     private slidingmenuadapter adapter;     private listview listviewsliding;     private drawerlayout drawerlayout;     private android.support.v7.app.actionbardrawertoggle actionbardrawertoggle;     private toolbar mtoolbar;      protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         butterknife.bind(this);           parseuser currentuser = parseuser.getcurrentuser();             //check see if user logged in             if (currentuser == null) {                 navigatetologin();  //if not, send them login page             }          else {  //if are, send username log (debug only)                 log.i(tag, currentuser.getusername());             }          listviewsliding = (listview)findviewbyid(r.id.lv_sliding_menu);         drawerlayout = (drawerlayout)findviewbyid(r.id.drawer_layout);         listsliding = new arraylist<>();         //add item sliding list         listsliding.add(new itemslidemenu(r.drawable.ic_action_settings, "map"));         listsliding.add(new itemslidemenu(r.drawable.ic_action_about, "emergency call"));         listsliding.add(new itemslidemenu(r.drawable.ic_account_plus_black_48dp, "friends"));         listsliding.add(new itemslidemenu(r.drawable.ic_logout_black_48dp, "log out"));          adapter = new slidingmenuadapter(this, listsliding);         listviewsliding.setadapter(adapter);          //display icon open/close slider         mtoolbar = (toolbar) findviewbyid(r.id.toolbar);         setsupportactionbar(mtoolbar);         mtoolbar.setbackgroundcolor(color.dkgray);         mtoolbar.settitletextcolor(color.black);         assert getsupportactionbar() != null;         getsupportactionbar().setdisplayhomeasupenabled(true);          //item selected         listviewsliding.setitemchecked(0, true);         //close menu         drawerlayout.closedrawer(listviewsliding);         //handle on item click         //at point may make sense change sort item id instead of position         listviewsliding.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> parent, view view, int position, long id) {                 if (position == 3) {                     parseuser.logout();                     navigatetologin();                 } else {                      //replace fragment                     replacefragment(position);                     //item selected                     listviewsliding.setitemchecked(position, true);                     //close menu                     drawerlayout.closedrawer(listviewsliding);                 }             }          });          actionbardrawertoggle = new actionbardrawertoggle(this, drawerlayout, r.string.drawer_opened, r.string.drawer_closed) {             @override             public void ondraweropened(view drawerview) {                 super.ondraweropened(drawerview);                 invalidateoptionsmenu();             }              @override             public void ondrawerclosed(view drawerview) {                 super.ondrawerclosed(drawerview);                 invalidateoptionsmenu();             }         };          drawerlayout.setdrawerlistener(actionbardrawertoggle);      }      private void navigatetologin() {         intent intent = new intent(this, loginactivity.class);         //these flags remove mainactivity history, can't way mainactivity login screen         intent.addflags(intent.flag_activity_new_task);         intent.addflags(intent.flag_activity_clear_task);         startactivity(intent);     }      @override     protected void onpostcreate(bundle savedinstancestate) {         super.onpostcreate(savedinstancestate);         actionbardrawertoggle.syncstate();     } //create method replace fragment     private void replacefragment(int position) {         android.support.v4.app.fragment fragment = null;         switch (position) {             case 0:                 fragment = new fragment1();                     break;             case 1:                 fragment = new fragment2();                 break;             case 2:                 fragment = new fragment3();                 break;             default:                 fragment = new fragment1();                 break;         }         if(null != fragment) {             android.support.v4.app.fragmentmanager fragmentmanager = getsupportfragmentmanager();             android.support.v4.app.fragmenttransaction transaction = fragmentmanager.begintransaction();             transaction.replace(r.id.main_content, fragment);             transaction.addtobackstack(null);             transaction.commit();          }     } } 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android"              android:layout_width="match_parent"              android:layout_height="match_parent">  <android.support.v4.widget.drawerlayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/drawer_layout"     tools:context="me.paxana.alerta.mainactivity">      <relativelayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:id="@+id/main_content"         android:layout_alignparenttop="true">     </relativelayout>      <listview         android:layout_width="200dp"         android:layout_height="match_parent"         android:id="@+id/lv_sliding_menu"         android:background="#ffffff"         android:choicemode="singlechoice"         android:layout_gravity="start"         android:paddingtop="?attr/actionbarsize"/> </android.support.v4.widget.drawerlayout>      <android.support.v7.widget.toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="?attr/actionbarsize"         android:minheight="?attr/actionbarsize"/>     </framelayout> 

i googled mike's answer , found needed do. added

@override     public boolean onoptionsitemselected(menuitem item) {          if(actionbardrawertoggle.onoptionsitemselected(item)) {             return true;         }         return super.onoptionsitemselected(item);     } 

i had deleted code when got rid of overflow menu.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -