通知显示在标签栏的android标签、通知、android

2023-09-06 07:24:47 作者:穷嘚瑟

我开发一个Android应用程序具有的TabBar在这一个选项卡的通知。我必须以显示正等待该用户我想显示挂起的请求的数量的通知的数量要在图标上显示出来。

I am developing an android app which has tabbar in it one tab is notification . I have to display the number of notifications that are pending to that user i want to display the number of pending request is to be displayed on the icon.

有通知的活动,显示通知的未决我需要把该选项卡中的计数tabbar.Icon数我是一平方和放大器;我想提出的数字到广场,但我没能做到这一点是没有任何notifiaction API,它给了我,伯爵也把在任何一个ViewGroup。

me having an activity of notification which shows number of notifications pending i need to put that count in tabbar.Icon of that tab is one square & i want to put digit to that square but i am not able to do that is there any notifiaction api which gives me that count also put in that any viewgroup.

日Thnx任何帮助...............

thnx for any help...............

推荐答案

这是一个例子如何添加徽章在标签

chat_tab.xml

chat_tab.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dip" 
    android:layout_height="64dip"
    android:layout_weight="1" 
    android:layout_marginLeft="-3dip" 
    android:layout_marginRight="-3dip" 
    android:orientation="vertical" 
    android:background="@drawable/tab_indicator" >

    <ImageView
        android:id="@+id/chat_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/chat_icon"
        android:layout_centerHorizontal="true"/>

    <TextView
        android:id="@+id/new_notifications" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/chat_icon"
        android:layout_toRightOf="@+id/chat_icon"
        android:layout_marginLeft="-8dp"
        android:layout_marginTop="0dp"
        android:paddingTop="2dp"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:paddingBottom="2dp"
        android:textSize="8sp"
        android:textStyle="bold"
        android:textColor="@android:color/primary_text_dark"
        android:background="@drawable/badge"
        android:visibility="gone"/>

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/chat"
        style="@android:attr/tabWidgetStyle"
        android:textColor="@android:color/tab_indicator_text"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"/>


</RelativeLayout>

这是 badge.xml (红色圆圈通知的背景),TextView的ID:new_notifications背景

This is badge.xml (red circle for notifications background),TextView id:new_notifications background

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="oval" >

    <stroke android:width="2dp" android:color="#FFFFFF" />

    <corners android:radius="10dp"/>

    <padding android:left="2dp" />

    <solid android:color="#ff2233"/>

</shape>

然后在code,你可以简单地做

Then in the code you can simply do

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View chatTab = inflater.inflate(R.layout.chat_tab, null);

        tvNewNotifications = (TextView) chatTab.findViewById(R.id.new_notifications);

        intent = new Intent().setClass(MainTab.this, Chat.class);
        tabSpec = tabHost
                .newTabSpec("chat")
                .setIndicator(chatTab)
                .setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));

正如你可以看到我的相对布局具有背景 @绘制/ tab_indicator 在标签indicator.xml 是框架的标准选项卡的绘制,这是我从SDK中得到的,我建议你也应该把它从SDK API的文件夹,你还需要一些图像的绘制文件夹复制,你可以找到它 your_sdk_drive:\ SDK \平台\ android的-8

As you can see my Relative Layout has a background @drawable/tab_indicator the tab indicator.xml is the framework's standard drawable of the tab,which i got from the sdk,i suggest you should also get it from the folder of the api in sdk as you also need to copy some images from the drawable folders,you can find it your_sdk_drive:\sdk\platforms\android-8