简体   繁体   中英

show unread notifications dynamically in footer android?

my requirement is to show unread notification count on footer like this: http://i.stack.imgur.com/IOaK0.jpg

am new to android and i really have no idea how to achieve this, i googled for this but not getting results.

this is my footer.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/footer_1"
    android:layout_width="fill_parent"
    android:layout_height="56dp"
    android:layout_alignParentBottom="true"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:background="@color/footer_bg"
        android:clickable="true"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/footer_background"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:orientation="vertical"
            android:padding="5dp" >

            <ImageView
                android:id="@+id/footer_home_icon"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:clickable="true"
                android:duplicateParentState="true"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:src="@drawable/home_menu" />

            <TextView
                android:id="@+id/footer_home"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:duplicateParentState="true"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="center"
                android:text="@string/footer_home"
                android:textColor="@drawable/footer_text"
                android:textSize="@dimen/footer_text" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/alert_layout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/footer_background"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:orientation="vertical"
            android:padding="5dp" >

            <ImageView
                android:id="@+id/footer_alert_icon"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:clickable="true"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:src="@drawable/alert_menu" />

            <TextView
                android:id="@+id/footer_alert"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="center"
                android:text="@string/footer_alert"
                android:textColor="@drawable/footer_text"
                android:textSize="@dimen/footer_text" />
        </LinearLayout>
</LinearLayout>

can anyone please tell me how i can do this?

Many thanks in advanced!!

You can create a layout like below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer_1"
android:layout_width="fill_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:background="@android:color/darker_gray"
    android:clickable="true"
    android:orientation="horizontal" >

    <RelativeLayout
        android:id="@+id/main_widget3"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal|center_vertical"
        android:layout_weight="0.5"
        android:background="@android:color/holo_blue_dark"
        android:focusable="true" >

        <ImageView
            android:id="@+id/icon3"
            android:layout_width="wrap_content"
            android:layout_height="30dip"
            android:layout_centerInParent="true"
            android:layout_marginTop="8dp"
            android:background="@drawable/brisbane"
            android:contentDescription="image"
            android:scaleType="center" />

        <TextView
            android:id="@+id/footer_alert3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/icon3"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="center"
            android:text="Brisbane"
            android:textColor="@android:color/black"
            android:textSize="10dip" />

        <TextView
            android:id="@+id/txt_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="-10dip"
            android:layout_toRightOf="@+id/icon3"
            android:background="@drawable/badge_count3"
            android:contentDescription="badge"
            android:gravity="center"
            android:text="1"
            android:textColor="@color/White"
            android:textStyle="bold"
            android:visibility="gone" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/main_widget2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal|center_vertical"
        android:layout_weight="0.5"
        android:background="@android:color/holo_blue_bright"
        android:focusable="true" >

        <ImageView
            android:id="@+id/icon2"
            android:layout_width="wrap_content"
            android:layout_height="30dip"
            android:layout_centerInParent="true"
            android:layout_marginTop="8dp"
            android:background="@drawable/bike"
            android:contentDescription="image"
            android:scaleType="center" />

        <TextView
            android:id="@+id/footer_alert2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/icon2"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="center"
            android:text="Bike"
            android:textColor="@android:color/black"
            android:textSize="10dip" />

        <TextView
            android:id="@+id/txt_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="-10dip"
            android:layout_toRightOf="@+id/icon2"
            android:background="@drawable/badge_count3"
            android:contentDescription="badge"
            android:gravity="center"
            android:text="1"
            android:textColor="@color/White"
            android:textStyle="bold"
            android:visibility="visible" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/main_widget"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_dark"
        android:layout_gravity="center_horizontal|center_vertical"
        android:layout_weight="0.5"
        android:focusable="true" >

        <ImageView
            android:id="@+id/icon"
            android:layout_width="wrap_content"
            android:layout_height="30dip"
            android:layout_centerInParent="true"
            android:layout_marginTop="8dp"
            android:background="@drawable/bowls"
            android:contentDescription="image"
            android:scaleType="center" />

        <TextView
            android:id="@+id/footer_alert"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/icon"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="center"
            android:text="Bowls"
            android:textColor="@android:color/black"
            android:textSize="10dip" />

        <TextView
            android:id="@+id/txt_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="-10dip"
            android:layout_toRightOf="@+id/icon"
            android:background="@drawable/badge_count3"
            android:contentDescription="badge"
            android:gravity="center"
            android:text="1"
            android:textColor="@color/White"
            android:textStyle="bold"
            android:visibility="gone" />
    </RelativeLayout>
</LinearLayout>

badge_count2.xml file

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<solid android:color="@color/red" >
</solid>

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

<padding
    android:bottom="2dp"
    android:left="7dp"
    android:right="7dp"
    android:top="3dp" />

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

add red color into your string.xml file

<color name="red">#e50822</color>

and now you can visible or invisible this view as per your requirement. Customized by your self. Thnx Below snap have a look: 在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM