android - how can I change the color of the tabBar in tab fragment (Viewpager) -
i tried many times it's not ok. try change actionbar in mainactivity tabbar doesn't change, don't no how change it.
this code : mainactivivty
public class mainactivity extends fragmentactivity implements actionbar.tablistener { private viewpager viewpager; private actionbar actionbar; private tabspageradapter madapter; private string[] tabs = { "bài hát", "yêu thích"}; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); actionbar ac = getactionbar(); ac.setbackgrounddrawable(new colordrawable(color.rgb(72, 209, 204))); //ac.setbackgrounddrawable(new colordrawable(color.parsecolor("#e64260"))); viewpager = (viewpager) findviewbyid(r.id.pager); actionbar = getactionbar(); madapter = new tabspageradapter(getsupportfragmentmanager()); viewpager.setadapter(madapter); actionbar.setnavigationmode(actionbar.navigation_mode_tabs); (string tab_name : tabs) { actionbar.addtab(actionbar.newtab().settext(tab_name) .settablistener(this)); } viewpager.setonpagechangelistener(new onpagechangelistener() { @override public void onpageselected(int position) { actionbar.setselectednavigationitem(position); if (position == 1) { tabyeuthich frag = (tabyeuthich) madapter .getfragmenttabyeuthich(1); frag.resetpage(); } else { tabbaihat frag = (tabbaihat) madapter .getfragmenttabbaihat(0); frag.resetpage(); } } @override public void onpagescrolled(int arg0, float arg1, int arg2) { } @override public void onpagescrollstatechanged(int arg0) { } }); } @override public void ontabreselected(tab tab, fragmenttransaction ft) { // todo auto-generated method stub } @override public void ontabselected(tab tab, fragmenttransaction ft) { // todo auto-generated method stub viewpager.setcurrentitem(tab.getposition()); } @override public void ontabunselected(tab tab, fragmenttransaction ft) { // todo auto-generated method stub }
this class : tabspageradapter
public class tabspageradapter extends fragmentpageradapter { fragmentmanager fm; tabyeuthich fragyeuthich; tabbaihat fragbaihat; public tabspageradapter(fragmentmanager fm) { super(fm); // todo auto-generated constructor stub this.fm = fm; } @override public fragment getitem(int index) { // todo auto-generated method stub switch (index) { case 0: fragbaihat = new tabbaihat(); return fragbaihat; case 1: fragyeuthich = new tabyeuthich(); return fragyeuthich; } return null; } @override public int getcount() { // todo auto-generated method stub return 2; } public fragment getfragmenttabyeuthich(int post) { return fragyeuthich; } public fragment getfragmenttabbaihat(int post) { return fragbaihat; }
please me ! !
useally set action bar themes.xml recommend follow both tutorials
Comments
Post a Comment