android - Bar status not changing color and ActionBar good practices -


i'm quite new in world of android, , i'm not sure how modify action bar.

in case, main activity has framelayout switch between fragments navigation drawer.

i've seen there several ways change actionbar parameters, i'm not quite sure 1 best. i'm using far change actionbar (and fragment) following:

@targetapi(build.version_codes.honeycomb)     public void displayview(int position) {         // update main content replacing fragment         fragment fragment = null;         imageview imageview = new imageview(getsupportactionbar().getthemedcontext());         imageview.setscaletype(imageview.scaletype.center);         switch (position) {             case 0:                 imageview.setimageresource(r.drawable.ic_launcher);                 getsupportactionbar().setbackgrounddrawable(new colordrawable(getresources().getcolor(r.color.main_menu)));                 fragment = new seccion1mainmenu();                 break;             case 1:                 imageview.setimageresource(r.drawable.ic_security);                 getsupportactionbar().setbackgrounddrawable(new colordrawable(getresources().getcolor(r.color.security_menu)));                 fragment = new seccion2security();                 break;             case 2:                 imageview.setimageresource(r.drawable.ic_light);                 getsupportactionbar().setbackgrounddrawable(new colordrawable(getresources().getcolor(r.color.light_menu)));                 fragment = new seccion3();                 break;             case 3:                 imageview.setimageresource(r.drawable.ic_fan);                 getsupportactionbar().setbackgrounddrawable(new colordrawable(getresources().getcolor(r.color.fan_menu)));                 fragment = new seccion4();                 break;              default:                 imageview.setimageresource(r.drawable.ic_launcher);                 break;         }         if (fragment != null) {             fragmentmanager fragmentmanager = getfragmentmanager();             fragmentmanager.begintransaction()                     .replace(r.id.frame_container, fragment).commit();              // update selected item , title, close drawer             mdrawerlist.setitemchecked(position, true);             mdrawerlist.setselection(position);             getsupportactionbar().setcustomview(imageview);             settitle(navmenutitles[position]);             mdrawerlayout.closedrawer(mdrawerlist);         } else {             // error in creating fragment             log.e("alvaro", "mainactivity - error cuando se creo el fragment");         } 

as can see in code, change color of action bar, title , image. proper way change modify content or i'm forcing machine?

what can't manage change color of status bar autmatically. i've read several posts , haven't been able achieve it. 1 of solutions proposed add line:

getwindow().addflags(windowmanager.layoutparams.flag_draws_system_bar_backgrounds); 

but got no result. have idea? :)

for status bar:

this 1 work me

//changing statusbar if (android.os.build.version.sdk_int >= 21){                 window window = this.getwindow();                 window.addflags(windowmanager.layoutparams.flag_draws_system_bar_backgrounds);                 window.clearflags(windowmanager.layoutparams.flag_translucent_status);                 window.setstatusbarcolor(this.getresources().getcolor(r.color.primary_dark));             } 

hope


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -