java - Navigation drawer and Action bar tabs contents overlapping in android -
i have done navigation drawer , action bar tabs using fragments contents of navigationdrawer
overlapping on actionbartabs
content.how overcome problem , work google play store app.
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); actionbar actionbar = getactionbar(); actionbar.setnavigationmode(actionbar.navigation_mode_tabs); // create new tabs , and set titles of tabs actionbar.tab mfindtab = actionbar.newtab().settext(getstring(r.string.ui_tabname_find)); actionbar.tab mchattab = actionbar.newtab().settext(getstring(r.string.ui_tabname_chat)); actionbar.tab mmeettab = actionbar.newtab().settext(getstring(r.string.ui_tabname_meet)); actionbar.tab mpartytab = actionbar.newtab().settext(getstring(r.string.ui_tabname_party)); // create fragments fragment mfindfragment = new findfragment(); fragment mchatfragment = new chatfragment(); fragment mmeetfragment = new meetfragment(); fragment mpartyfragment = new partyfragment(); // bind fragments tabs - set tablisteners each tab mfindtab.settablistener(new mytabslistener(mfindfragment,getapplicationcontext())); mchattab.settablistener(new mytabslistener(mchatfragment,getapplicationcontext())); mmeettab.settablistener(new mytabslistener(mmeetfragment,getapplicationcontext())); mpartytab.settablistener(new mytabslistener(mpartyfragment,getapplicationcontext())); // add tabs action bar actionbar.addtab(mfindtab); actionbar.addtab(mchattab); actionbar.addtab(mmeettab); actionbar.addtab(mpartytab); if (savedinstancestate != null) { toast.maketext(getapplicationcontext(), "tab " + savedinstancestate.getint(tab_key_index, 0), toast.length_short).show(); actionbar.setselectednavigationitem(savedinstancestate.getint( tab_key_index, 0)); } datalist = new arraylist<draweritem>(); mtitle = mdrawertitle = gettitle(); mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout); mdrawerlist = (listview) findviewbyid(r.id.left_drawer); mdrawerlayout.setdrawershadow(r.drawable.drawer_shadow,gravitycompat.start); datalist.add(new draweritem("notifications", r.drawable.ic_action_email)); datalist.add(new draweritem("messages", r.drawable.ic_action_good)); datalist.add(new draweritem("today's task you", r.drawable.ic_action_gamepad)); datalist.add(new draweritem("milestone", r.drawable.ic_action_labels)); datalist.add(new draweritem("your working on", r.drawable.ic_action_search)); datalist.add(new draweritem("calender", r.drawable.ic_action_cloud)); datalist.add(new draweritem("leaderboard", r.drawable.ic_action_camera)); datalist.add(new draweritem("your score", r.drawable.ic_action_video)); datalist.add(new draweritem("your productivity", r.drawable.ic_action_group)); datalist.add(new draweritem("your badges",r.drawable.ic_action_import_export)); datalist.add(new draweritem("your skills cloud", r.drawable.ic_action_about)); datalist.add(new draweritem("your strength", r.drawable.ic_action_settings)); datalist.add(new draweritem("your weakness", r.drawable.ic_action_help)); adapter = new customdraweradapter(this, r.layout.custom_drawer_item,datalist); mdrawerlist.setadapter(adapter); mdrawerlist.setonitemclicklistener(new draweritemclicklistener()); getactionbar().setdisplayhomeasupenabled(true); getactionbar().sethomebuttonenabled(true); mdrawertoggle = new actionbardrawertoggle(this, mdrawerlayout,r.drawable.ic_drawer, r.string.drawer_open,r.string.drawer_close) { public void ondrawerclosed(view view) { getactionbar().settitle(mtitle); invalidateoptionsmenu(); } public void ondraweropened(view drawerview) { getactionbar().settitle(mdrawertitle); invalidateoptionsmenu(); } }; mdrawerlayout.setdrawerlistener(mdrawertoggle); if (savedinstancestate == null) { selectitem(0); } } class mytabslistener implements actionbar.tablistener { public fragment fragment; public context context; public mytabslistener(fragment fragment, context context) { this.fragment = fragment; this.context = context; } @override public void ontabreselected(tab tab, fragmenttransaction ft) { toast.maketext(context, "reselected!", toast.length_short).show(); } @override public void ontabselected(tab tab, fragmenttransaction ft) { toast.maketext(context, "selected!", toast.length_short).show(); ft.replace(r.id.fragment_container, fragment); } @override public void ontabunselected(tab tab, fragmenttransaction ft) { toast.maketext(context, "unselected!", toast.length_short).show(); ft.remove(fragment); } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center"> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" > </linearlayout> <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <framelayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <listview android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choicemode="singlechoice" android:divider="@android:color/transparent" android:dividerheight="0dp" android:background="#ffff"/> </android.support.v4.widget.drawerlayout> </linearlayout>
Comments
Post a Comment