In Android, how to get default focus on Back/Home button on ActionBar -


i have fragment extending preferencefragment, how default focus on back/home button in actionbar.

at present default focus on first entry in list.

tried below code in main activity well, gave null pointer exception,

view home = findviewbyid(android.r.id.home); home.requestfocus();

can try following? (it's more of hack, underlying assumption home button first child)

private void requestbackbuttonfocus() {     if (toolbar != null) {         int childrencount = toolbar.getchildcount();         (int = 0; < childrencount; i++) {             if (toolbar.getchildat(i) instanceof imagebutton) {                 toolbar.getchildat(i).requestfocus();                 break;             }         }     } } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -