我正在构建聊天应用程序。在我的应用程序中,我使用 View Pager 和PagerSlidingTabStrip。下面是快照。
现在,当我收到来自用户的新消息时,我想在最近的选项卡上显示数字计数器
。
请帮助我,我已经被困在这一点上很多天了。
谢谢
我正在构建聊天应用程序。在我的应用程序中,我使用 View Pager 和PagerSlidingTabStrip。下面是快照。
现在,当我收到来自用户的新消息时,我想在最近的选项卡上显示数字计数器
。
请帮助我,我已经被困在这一点上很多天了。
谢谢
我是通过自定义视图做到的。编辑 PagerSlidingTabStrip.java 文件,如下所示。
private void addIconTab(final int position, int resId) {
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.image_tab, null);
ImageButton tab = (ImageButton)view.findViewById(R.id.img_icon);
tab.setImageResource(resId);
addTab(position, view);
}
如果您使用文本选项卡,请修改 addTextTab() 方法。
和 layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/img_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:layout_centerInParent="true"
android:background="@null"
android:clickable="false" />
<TextView
android:id="@+id/tv_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:background="@drawable/bg_number"
android:gravity="center"
android:text="33" />
</RelativeLayout>