On Android Drawer Two icons Appear on ActionBar, Need Only One Icon -
i implementing navigation drawer in android app. problem 2 icons appear on actionbar. have added actionbardrawertoggle , seems second icon displayed actionbardrawertoggle. please tell me error in code.
please tell me wheat error.
and here complete code
package com.example.newdrawer; import android.os.bundle; import android.app.activity; import android.content.res.configuration; import android.support.v4.app.actionbardrawertoggle; import android.support.v4.widget.drawerlayout; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.adapterview; import android.widget.arrayadapter; import android.widget.listview; import android.widget.toast; public class mainactivity extends activity { drawerlayout mdrawerlayout; actionbardrawertoggle mactionbardrawertoggle; listview listview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); getactionbar().seticon(r.drawable.ic_launcher); string[] listitems = {"first", "second", "third"}; listview = (listview) findviewbyid(r.id.drawer); listview.setadapter(new arrayadapter<string>(this, r.layout.list_item, r.id.textview1, listitems)); listview.setonitemclicklistener(new draweritemclicklistener()); getactionbar().setdisplayhomeasupenabled(true); getactionbar().sethomebuttonenabled(true); mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout); mactionbardrawertoggle = new actionbardrawertoggle( this, /* host activity */ mdrawerlayout, /* drawerlayout object */ r.drawable.ic_launcher, /* nav drawer icon replace 'up' caret */ r.string.drawer_opened, /* "open drawer" description */ r.string.drawer_closed /* "close drawer" description */ ) { /** called when drawer has settled in closed state. */ public void ondrawerclosed(view view) { super.ondrawerclosed(view); getactionbar().settitle("appname"); } /** called when drawer has settled in open state. */ public void ondraweropened(view drawerview) { super.ondraweropened(drawerview); getactionbar().settitle("select item"); } }; mdrawerlayout.setdrawerlistener(mactionbardrawertoggle); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.activity_main, menu); return true; } // change caret @override protected void onpostcreate(bundle savedinstancestate) { super.onpostcreate(savedinstancestate); // sync toggle state after onrestoreinstancestate has occurred. mactionbardrawertoggle.syncstate(); } @override public void onconfigurationchanged(configuration newconfig){ super.onconfigurationchanged(newconfig); mactionbardrawertoggle.onconfigurationchanged(newconfig); } @override public boolean onoptionsitemselected(menuitem item) { // action bar home/up action should open or close drawer. // actionbardrawertoggle take care of this. if (mactionbardrawertoggle.onoptionsitemselected(item)) { return true; } return super.onoptionsitemselected(item); } // navigation drawer click listener private class draweritemclicklistener implements listview.onitemclicklistener { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { toast.maketext(mainactivity.this, "you clicked:"+string.valueof(position), toast.length_long).show(); mdrawerlayout.closedrawers(); } } }
here xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity" > <android.support.v4.widget.drawerlayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:layout_width = "match_parent" android:layout_height= "match_parent" android:id = "@+id/text1" android:text = "hello world"/> <listview android:id="@+id/drawer" android:layout_width = "210dp" android:layout_height = "match_parent" android:layout_gravity = "start" android:background="@android:color/white"/> </android.support.v4.widget.drawerlayout>" </linearlayout>
thank in advance
the first icon supposed drawer icon (aka hamburger). replaced launcher icon
mactionbardrawertoggle = new actionbardrawertoggle( this, /* host activity */ mdrawerlayout, /* drawerlayout object */ r.drawable.r.drawable.ic_launcher, /* nav drawer icon replace 'up' caret */ r.string.drawer_opened, /* "open drawer" description */ r.string.drawer_closed /* "close drawer" description */ )
replace r.drawable.ic_launcher
actual drawer icon resource in code above.
Comments
Post a Comment