Android drawer App icon not showing up - Incompatibility between Theme.AppCompat.Light and ActionBarActivity: -
i'm trying implement navigation drawer on app extending actionbaractivity , using theme.appcompat.light. screen 1 in post drawer icon not left aligned , launcher icon not showing
the app icon doesn't show , ic_drawer icon not correctly aligned. i've seen posts same problem none of them got response use.
i've spent week on issue no results.
thank in advance.
bellow code:
public class navigationdraweractivity extends actionbaractivity { private string[] mnavigationdraweritemtitles; private drawerlayout mdrawerlayout; private listview mdrawerlist; private charsequence mdrawertitle; private charsequence mtitle; //for app icon control nav drawer actionbardrawertoggle mdrawertoggle; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_navigation_drawer); mnavigationdraweritemtitles= getresources().getstringarray(r.array.navigation_drawer_items_array); mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout); mdrawerlist = (listview) findviewbyid(r.id.left_drawer); // set custom shadow overlays main content when drawer opens mdrawerlayout.setdrawershadow(r.drawable.drawer_shadow, gravitycompat.start); objectdraweritem[] draweritem = new objectdraweritem[3]; draweritem[0] = new objectdraweritem(r.drawable.ic_action_camera, "my pets"); draweritem[1] = new objectdraweritem(r.drawable.ic_drawer, "married"); draweritem[2] = new objectdraweritem(r.drawable.ic_action_help, "help"); //pass list of drawer items draweritemcustomadapter draweritemcustomadapter adapter = new draweritemcustomadapter(this, r.layout.drawer_listview_item_row, draweritem); //set adapter mdrawerlist.setadapter(adapter); //set item click listener mdrawerlist.setonitemclicklistener(new draweritemclicklistener()); //set properties proper title display mtitle = mdrawertitle = gettitle(); //add app icon control code mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout); mdrawertoggle = new actionbardrawertoggle( this, mdrawerlayout, r.drawable.ic_drawer, r.string.drawer_open, r.string.drawer_close ) { /** called when drawer has settled in closed state. */ public void ondrawerclosed(view view) { super.ondrawerclosed(view); getsupportactionbar().settitle(mtitle); } /** called when drawer has settled in open state. */ public void ondraweropened(view drawerview) { super.ondraweropened(drawerview); getsupportactionbar().settitle(mdrawertitle); } }; mdrawerlayout.setdrawerlistener(mdrawertoggle); getsupportactionbar().setdisplayhomeasupenabled(true); getsupportactionbar().sethomebuttonenabled(true); //getsupportactionbar().seticon(r.drawable.ic_launcher); //getsupportactionbar().setdisplayshowhomeenabled(true); } private class draweritemclicklistener implements listview.onitemclicklistener { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { selectitem(position); } } private void selectitem(int position) { fragment fragment = null; switch (position) { case 0: fragment = new mypetlistfragment(); break; case 1: fragment = new mypetmarriedfragment(); break; case 2: fragment = new mypetmarriedfragment(); break; default: break; } if (fragment != null) { fragmentmanager fragmentmanager = getfragmentmanager(); fragmentmanager.begintransaction().replace(r.id.content_frame, fragment).commit(); mdrawerlist.setitemchecked(position, true); mdrawerlist.setselection(position); settitle(mnavigationdraweritemtitles[position]); mdrawerlayout.closedrawer(mdrawerlist); } else { log.e("mainactivity", "error in creating fragment"); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_navigation_drawer, menu); //menu.finditem(r.id.action_settings).setvisible(true); return true; } /* called whenever call invalidateoptionsmenu() */ @override public boolean onprepareoptionsmenu(menu menu) { // if nav drawer open, hide action items related content view boolean draweropen = mdrawerlayout.isdraweropen(mdrawerlist); menu.finditem(r.id.action_help).setvisible(!draweropen); return super.onprepareoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. if (mdrawertoggle.onoptionsitemselected(item)) { return true; } // handle action bar actions click switch (item.getitemid()) { case r.id.action_help: toast.maketext(getapplicationcontext(), "help pressed", toast.length_long).show(); return true; default: return super.onoptionsitemselected(item); } } @override //this needed changing titles. public void settitle(charsequence title) { mtitle = title; getsupportactionbar().settitle(mtitle); } @override protected void onpostcreate(bundle savedinstancestate) { super.onpostcreate(savedinstancestate); // sync toggle state after onrestoreinstancestate has occurred. mdrawertoggle.syncstate(); } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); // pass configuration change drawer toggles mdrawertoggle.onconfigurationchanged(newconfig); } }`
and styles.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- theme applied application or activity --> <style name="apptheme" parent="@style/theme.appcompat.light"> <item name="android:actionbarstyle">@style/myactionbar</item> <item name="android:actionbartabtextstyle">@style/myactionbartabtext</item> <item name="android:actionmenutextcolor">@color/blue</item> <!-- support library compatibility --> <item name="actionbarstyle">@style/myactionbar</item> <item name="actionbartabtextstyle">@style/myactionbartabtext</item> <item name="actionmenutextcolor">@color/blue</item> <item name="toolbarstyle">@style/mytoolbarstyle</item> <item name="toolbarnavigationbuttonstyle">@style/mytoolbarnavigationbuttonstyle</item> </style> <!-- actionbar styles --> <style name="myactionbar" parent="@style/widget.appcompat.light.actionbar.solid.inverse"> <item name="android:titletextstyle">@style/myactionbartitletext</item> <item name="android:background">@color/darkbrown</item> <!-- support library compatibility --> <item name="titletextstyle">@style/myactionbartitletext</item> <item name="background">@color/darkbrown</item> </style> <!-- actionbar title text --> <style name="myactionbartitletext" parent="@style/textappearance.appcompat.widget.actionbar.title"> <item name="android:textcolor">@color/darkblue</item> <!-- textcolor property backward compatible support library --> </style> <style name="mytoolbarnavigationbuttonstyle" parent="@style/widget.appcompat.toolbar.button.navigation"> <item name="android:minwidth">0dp</item> <item name="android:padding">12dp</item> <item name="android:scaletype">centerinside</item> </style> <style name="mytoolbarstyle" parent="@style/widget.appcompat.toolbar"> <item name="android:paddingright">0dp</item> </style> <!-- actionbar tabs text --> <style name="myactionbartabtext" parent="@style/widget.appcompat.actionbar.tabtext"> <item name="android:textcolor">@color/darkred</item> <!-- textcolor property backward compatible support library --> </style> <style name="text.small" parent="@android:style/textappearance"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textcolor">@color/browntext</item> <item name="android:typeface">monospace</item> <item name="android:textsize">10sp</item> </style> <style name="text.small.black" parent="@android:style/textappearance"> <item name="android:textcolor">@color/black</item> </style> <style name="text.medium" parent="@android:style/textappearance"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textcolor">@color/browntext</item> <item name="android:typeface">monospace</item> <item name="android:textsize">20sp</item> </style> <style name="text.big" parent="@android:style/textappearance"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textcolor">@color/browntext</item> <item name="android:typeface">monospace</item> <item name="android:textsize">30sp</item> </style> </resources>
Comments
Post a Comment