Android ViewDrawer homebutton -
i'm trying create viewdrawer support-lib actionbaractivity. layout looks
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_container" android:layout_width="match_parent" android:layout_height="match_parent" > <framelayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" /> <include android:id="@+id/drawer_view" android:layout_width="@dimen/drawer_width" android:layout_height="match_parent" android:layout_gravity="start" layout="@layout/include_drawer" /> </android.support.v4.widget.drawerlayout>
and activity looks this:
public abstract class baseactivity extends basesimpleactivity { public static final string fragment_tag = "content"; protected drawerlayout mdrawerlayout; protected actionbardrawertoggle mdrawertoggle; protected listview mdrawerlist; protected viewgroup mdrawerview; protected view mdrawerbtnsettings; private handler mhandler; @override protected void oncreate(bundle savedinstancestate) { ... } protected void initviews(string title, fragment fragment) { setcontentview(r.layout.activity_base_secondary); getsupportfragmentmanager().begintransaction().replace(r.id.content, fragment, fragment_tag).commit(); initdrawer(); initactionbar(); } protected void settitle(string title) { super.settitle(title); getsupportactionbar().settitle(title); } private void initactionbar() { android.support.v7.app.actionbar actionbar = getsupportactionbar(); actionbar.setdisplayoptions(actionbar.display_home_as_up); //actionbar.seticon(r.drawable.ic_launcher); actionbar.setdisplayshowtitleenabled(false); actionbar.setdisplayshowcustomenabled(true); actionbar.setcustomview(r.layout.action_bar); textview title = (textview) actionbar.getcustomview().findviewbyid(r.id.actionbartitle); title.settext(gettitleresid()); title.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (mdrawerlayout.isdraweropen(gravity.start)) { mdrawerlayout.closedrawers(); } else { mdrawerlayout.opendrawer(gravity.start); } } }); refreshactionbar(); } public abstract string gettitleresid(); private void initdrawer() { mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_container); mdrawerview = (viewgroup) findviewbyid(r.id.drawer_view); mdrawerlist = (listview) findviewbyid(r.id.drawer_list); mdrawerlist.setadapter(new drawerlistadapter(this)); mdrawerlist.setonitemclicklistener(new draweritemclicklistener()); mdrawertoggle = createdrawertoggle(); mdrawerlayout.setdrawerlistener(mdrawertoggle); mdrawerbtnsettings = findviewbyid(r.id.drawer_settings); refreshdrawer(); } private actionbardrawertoggle createdrawertoggle() { homecoming new actionbardrawertoggle(this, mdrawerlayout, r.drawable.ic_drawer, r.string.drawer_open, r.string.drawer_close); } @override public boolean onprepareoptionsmenu(menu menu) { refreshactionbar(); int size = menu.size(); mmenuitemids = new int[size]; (int = 0; < size; i++) { mmenuitemids[i] = menu.getitem(i).getitemid(); } homecoming super.onprepareoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { if (mdrawertoggle.onoptionsitemselected(item)) { homecoming true; } homecoming super.onoptionsitemselected(item); } @override protected void onpostcreate(bundle savedinstancestate) { super.onpostcreate(savedinstancestate); mdrawertoggle.syncstate(); } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); mdrawertoggle.onconfigurationchanged(newconfig); } protected boolean isdraweropen() { homecoming mdrawerlayout.isdraweropen(mdrawerview); } /** * update title , invalidate options menu */ protected void refreshactionbar() { if (isdraweropen()) { setactionbaritemsalpha(0); } else { getsupportactionbar().settitle(gettitle()); } } /** * update selected item. */ protected void refreshdrawer() { navigation id = navigation.getid(this); if(id != null) { mdrawerlist.setitemchecked(id.ordinal(), true); } } protected void ondraweritemclick(int which) { // override if subclass needs hear drawer click events } private class draweritemclicklistener implements listview.onitemclicklistener { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { selectdraweritem(position); } } protected void selectdraweritem(final int which) { navigation id = navigation.getid(this); if (id != null && == id.ordinal()) { return; } ondraweritemclick(which); mpendinglaunch = drawerutils.buildlaunchrunnable(this, which); mdrawerlayout.closedrawer(mdrawerview); } }
but can see on screenshot below icon drawer rendered on devices , on others not rendered @ all. when check in android monitor layout has width of zero. clues on whats going on?
if using v21 of appcompat, need utilize android.support.v7.app.actionbardrawertoggle rather deprecated v4 version using.
android
No comments:
Post a Comment