android - Indeterminate Horizontal ProgressBar BELOW ActionBar using AppCompat? -
i have been looking answers on how place indeterminate horizontal progress bar below action bar using appcompat. i'm able horizontal progress bar appear, @ top of action bar. want under/below action bar kind of how gmail (except without pull refresh).
i used following code have progress bar appear:
supportrequestwindowfeature(window.feature_progress); setcontentview(r.layout.main_activity); setsupportprogressbarindeterminate(boolean.true); setsupportprogressbarvisibility(true);
but places horizontal progress bar @ top of action bar. know how place progress bar below action bar?
i faced similar problem , solved creating own progressbar , aligning manipulating gettop() of content view.
so first create progressbar.
final layoutparams lp = new layoutparams(layoutparams.match_parent, 20); //use dp resources mloadingprogressbar = new progressbar(this, null, android.r.attr.progressbarstylehorizontal); mloadingprogressbar.setindeterminate(true); mloadingprogressbar.setlayoutparams(lp);
add window (decor view)
final viewgroup decor = (viewgroup) getwindow().getdecorview(); decor.addview(mloadingprogressbar);
and in order correct position im using viewtreeobserver
listens until view has been laid out (aka view.gettop() isnt 0).
final viewtreeobserver vto = decor.getviewtreeobserver(); vto.addongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener() { final view content = getview(android.r.id.content); @override public void ongloballayout() { int top = content.gettop(); //dont until gettop has value above 0. if (top == 0) return; //i use actionbar overlay in activities, //in cases it's size has accounted //otherwise progressbar show @ top of //rather under. if (getsherlock().hasfeature((int) window.feature_action_bar_overlay)) { top += getsupportactionbar().getheight(); } //remove listener, dont need anymore. utils.removeongloballayoutlistener(decor, this); //view.sety() if you're using api 11+, //i use nineoldandroids support older viewhelper.sety(mloadingprogressbar, top); } });
hope makes sense you. luck!
Comments
Post a Comment