PagerSlidingTabStrip:ViewPager徽章号码 [英] PagerSlidingTabStrip: ViewPager badge numbers
问题描述
我能够把证件号码上按钮
S等,但还有如何证件号码可以放置在一个视图寻呼机任何例子吗?对于按钮,我创建与适当的背景资源,等一个XML,但我无法找到任何方式将其放在 PagerSlidingTabStrip
。
I'm able to put badge numbers on Button
s, etc. but is there any example of how badge number can be placed on a view pager? For button I'm creating an xml with the proper background resource, etc. but i'm not able to find any way to place it on the PagerSlidingTabStrip
.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:background="@drawable/badge"
android:gravity="center"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:text="2"
android:textColor="@color/WHITE"
android:textSize="12sp"
android:textStyle="bold"
android:visibility="gone" />
我将该值设置为消失
第一,在需要时显示。有没有一种方法,以这样的观点,寻呼机做到这一点?
I set the value to gone
first and show when needed. Is there a way to do this with the view pager?
推荐答案
您应该做一个小的修改到 PagerSlidingTabStrip
。
You should do a small modification into the PagerSlidingTabStrip
.
将这块code到 PagerSlidingTabStrip
类:
public LinearLayout getTabsContainer(){
return tabsContainer;
}
现在您可以通过访问该标签的观点:
Now you are able to access the tabs views by :
查看currentTabView = pagerSlidingTabStrip.getTabsContainer()getChildAt(currentPosition);
您可以轻松地使用 <一个href="https://github.com/jgilfelt/android-viewbadger">https://github.com/jgilfelt/android-viewbadger ,按照下面的例子:
You can easily use the https://github.com/jgilfelt/android-viewbadger , follow the example below:
在MainActivity
公共静态视图currentTab;
私人PagerSlidingTabStrip pagerSlidingTabStrip;
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
currentTab = pagerSlidingTabStrip.getTabsContainer().getChildAt(0);
return firstFragment;
case 1:
currentTab = pagerSlidingTabStrip.getTabsContainer().getChildAt(1);
return secondFragment;
case 2:
currentTab = pagerSlidingTabStrip.getTabsContainer().getChildAt(2);
return thirdFragment;
}
return null;
}
在片段
BadgeView badge = new BadgeView(getActivity(), MainActivity.currentTab);
badge.setText("1"); //Whatever value you should add
badge.show();
这篇关于PagerSlidingTabStrip:ViewPager徽章号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!