java - Action Bar Home Button not functional with nested PreferenceScreen -
i found workaround enable actionbar home button on nested preferencescreen... doesn't call onoptionsitemselected in preferenceactivity. know way use home button on nested preferencescreen?
modification of post 35 here:
http://code.google.com/p/android/issues/detail?id=4611
@override public boolean onpreferencetreeclick(preferencescreen preferencescreen, preference preference) { super.onpreferencetreeclick(preferencescreen, preference); if (preference!=null) if (preference instanceof preferencescreen) if (((preferencescreen)preference).getdialog()!=null) ((preferencescreen)preference).getdialog().getactionbar().sethomebuttonenabled(true); return false; }
i had problem , how solved it. firstly access preferencescreen use exact same method mentioned above.
@override public boolean onpreferencetreeclick(preferencescreen preferencescreen, preference preference) { super.onpreferencetreeclick(preferencescreen, preference); // if user has clicked on preference screen, set action bar if (preference instanceof preferencescreen) { initializeactionbar((preferencescreen) preference); } return false; }
from here looked preferencescreen is, , saddened find out wrapper of dialog. moving forward, set actionbar display options , attempt find home button area. unfortunately wasn't easy get, of hierarchy viewer managed gain access finding home icon , parent views. once have access containing linearlayout, can attach onclicklistener dismiss preferencescreen's dialog, calls preferencescreen's ondismisslistener , returns previous screen.
/** sets action bar {@link preferencescreen} */ public static void initializeactionbar(preferencescreen preferencescreen) { final dialog dialog = preferencescreen.getdialog(); if (dialog != null) { // inialize action bar dialog.getactionbar().setdisplayhomeasupenabled(true); // apply custom home button area click listener close preferencescreen because preferencescreens dialogs swallow // events instead of passing activity // related issue: https://code.google.com/p/android/issues/detail?id=4611 view homebtn = dialog.findviewbyid(android.r.id.home); if (homebtn != null) { onclicklistener dismissdialogclicklistener = new onclicklistener() { @override public void onclick(view v) { dialog.dismiss(); } }; // prepare yourselves hacky programming viewparent homebtncontainer = homebtn.getparent(); // home button imageview inside framelayout if (homebtncontainer instanceof framelayout) { viewgroup containerparent = (viewgroup) homebtncontainer.getparent(); if (containerparent instanceof linearlayout) { // view contains title text, set whole view clickable ((linearlayout) containerparent).setonclicklistener(dismissdialogclicklistener); } else { // set on home button ((framelayout) homebtncontainer).setonclicklistener(dismissdialogclicklistener); } } else { // 'if else fails' default case homebtn.setonclicklistener(dismissdialogclicklistener); } } } }
Comments
Post a Comment