In this tutorial we are aiming to see a way to create Badge (Item Count) to a android Application. Badge is really used to show number of notification, message,product count .We can see many android app use Badge to their Application these days. there's no cutoff way to do it we'll do it by coding ourself. during this application we are aiming to see a way to create Badge in Image Button and button.

Requirement 


  1. JDK 7.0 or Above
  2. Android Studio 2.0

Steps to Follow:

Inside Drawable  folder  create an xml file item_count  and  create a rectangle with 8dp  corner radius.

item_count.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="#f20000" />
<stroke
android:width="2dip"
android:color="#FFF" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>

To modify   activity_main.xml  add  Relativelayout , Buttons and text . your activity_main.xml  will be like below. And  add the required images in the Drawable folder for this layout .

activity_main.xml 

<?xml version="1.0" encoding="utf-8"?>
<!--Adding Badge (Item Count)/Notification Count to Android Button-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="match_parent"
 android:gravity="center_horizontal"
 android:orientation="vertical"
 android:padding="16dp">

 <RelativeLayout
 android:id="@+id/badge_layout1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">
 
<RelativeLayout
android:id="@+id/relative_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<Button
 android:id="@+id/button1"
 android:layout_width="65dip"
 android:layout_height="65dip"
 android:background="@drawable/chat_icon" />
</RelativeLayout>

<TextView
 android:id="@+id/badge_notification_1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignRight="@id/relative_layout"
 android:background="@drawable/item_count"
 android:text="16"
 android:textColor="#FFF"
 android:textSize="16sp"
 android:textStyle="bold" />
</RelativeLayout>

<RelativeLayout
 android:id="@+id/badge2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginLeft="50dp"
 android:layout_toRightOf="@+id/badge_layout1">

 <RelativeLayout
 android:id="@+id/relative_layout1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">

 <Button
 android:id="@+id/myButton1"
 android:layout_width="65dip"
 android:layout_height="65dip"
 android:background="@drawable/email_icon" />
</RelativeLayout>

<TextView
 android:id="@+id/badge_notification_2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignRight="@id/relative_layout1"
 android:background="@drawable/item_count"
 android:text="21"
 android:textColor="#FFF"
 android:textSize="16sp"
 android:textStyle="bold" />
</RelativeLayout>
 
<RelativeLayout
  android:id="@+id/badge4"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@+id/badge_layout1"
  android:layout_marginTop="50dp">
 
<RelativeLayout
  android:id="@+id/relative_layout3"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
 
 <Button
  android:id="@+id/myButton4"
  android:layout_width="wrap_content"
  android:layout_height="65dip"
  android:background="#4169E1"
  android:elevation="4dp"
  android:paddingLeft="50dp"
  android:paddingRight="50dp"
  android:text="Notification"
  android:textColor="#fff" />
</RelativeLayout>
 
<TextView
  android:id="@+id/badge_notification_4"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignLeft="@id/relative_layout3"
  android:background="@drawable/item_count"
  android:text="427"
  android:textColor="#FFF"
  android:textSize="16sp"
  android:textStyle="bold" />
 </RelativeLayout>
</RelativeLayout>
 And your MainActivity.java  is default content as  below

MainActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Now run your application  , you will see the screensot like  below :

Demo

Hope you enjoy and tutorial is helpful for your project.

0

Add a comment

Easy Steps to Add 301 Redirects to WordPress
Easy Steps to Add 301 Redirects to WordPress
Is Purefit Keto Beneficial For Weight Loss?
Is Purefit Keto Beneficial For Weight Loss?
The Best SEO Practices for Blogging » Tell Me How - A Place for Technology Geekier
The Best SEO Practices for Blogging » Tell Me How - A Place for Technology Geekier
json2view : Some important properties and types » Tell Me How - A Place for Technology Geekier
json2view : Some important properties and types » Tell Me How - A Place for Technology Geekier
Yes You Can! How Millennials Can Actually Afford a House » Tell Me How - A Place for Technology Geekier
Yes You Can! How Millennials Can Actually Afford a House » Tell Me How - A Place for Technology Geekier
THE BEST GADGETS FOR STUDYING OF 2020 &raquo; Tell Me How - A Place for Technology Geekier
THE BEST GADGETS FOR STUDYING OF 2020 &raquo; Tell Me How - A Place for Technology Geekier
JDK Alternatives for Production
Transition Page Recycler using Animated Recycler View
Transition Page Recycler using Animated Recycler View
Best programming for Android after analyse APK
Best programming for Android after analyse APK
Top 6 Java Defects can resolve by Kotlin
Top 6 Java Defects can resolve by Kotlin
Magic Multiply by 9 Trick without Pen and Paper
Magic Multiply by 9 Trick without Pen and Paper
[CRUD Example] : Spring Boot with Kotlin and AngularJS
[CRUD Example] : Spring Boot with Kotlin and AngularJS
What is MVC, MVP and MVVM in details?
What is MVC, MVP and MVVM in details?
How to Add Popup Menu in Android?
How to Add Popup Menu in Android?
Top 5 Android and Kotlin Database Libraries
Top 5 Android and Kotlin Database Libraries
BlockChain Technology - Advantage and Disadvantage
BlockChain Technology - Advantage and Disadvantage
Android Technology Trends in 2018
Android Technology Trends in 2018
Comparison between all Android Wear Library
Comparison between all Android Wear Library
Multicolor TextView for Android
Multicolor TextView for Android
Nothing Type in Kotlin
Nothing Type in Kotlin
Advanced Kotlin Tips
Advanced Kotlin Tips
Awesome Kotlin Parcelize Feature - Need to Know
Awesome Kotlin Parcelize Feature - Need to Know
Create Food Order Tracking app using Android Timeline View Library
Create Food Order Tracking app using Android Timeline View Library
Let's build a Firefox extension with Kotlin
Justice League Reviews Round-up
Justice League Reviews Round-up
Google Pixel 2 XL vs iPhone X: Find out Best phone
Google Pixel 2 XL vs iPhone X: Find out Best phone
Password Recovery Reviews
Password Recovery Reviews
Which Android Dependency Injection is best?
Which Android Dependency Injection is best?
What is MVC, MVP and MVVM in details
What is MVC, MVP and MVVM in details
Google Play Protect – A New Way To Protect Your Phone
Google Play Protect – A New Way To Protect Your Phone
Some Kotlin Problem with solutions Every developer need to know
Some Kotlin Problem with solutions Every developer need to know
Best Android Animation Library in 2017
How to Implement Vega Scroll Layout Android Slider?
How to Implement Vega Scroll Layout Android Slider?
How to Add Android Rich Path Animator?
How to Add Android Rich Path Animator?
Topbar Menu with Guillotine Android animation
Topbar Menu with Guillotine Android animation
Implement Android Prevent Screen Off library?
Implement Android Prevent Screen Off library?
Android P support Java 9 with Kotlin updates?
Android P support Java 9 with Kotlin updates?
Tutorial : Create Augmented Reality in Kotlin
Anyone to Create Custom Ransomware Virus
Anyone to Create Custom Ransomware Virus
Android Oreo vs. iOS 11: The Next-Gen OS Battle
Android Oreo vs. iOS 11: The Next-Gen OS Battle
Android 7 Vs Android 8
Android 7 Vs Android 8
Google launched Android Oreo See the features
Google launched Android Oreo See the features
How to Android Image Compression Using ImageZipper Library?
How to Android Image Compression Using ImageZipper Library?
How to use FileStack File Picker for Cloud in Android
How to use FileStack File Picker for Cloud in Android
Create UberCar Animation with Android Library
Create UberCar Animation with Android Library
How to Add FloatingView Animation in Android?
How to Add FloatingView Animation in Android?
Add Material Shadow in Android
Add Material Shadow in Android
Daily used Kotlin Code Snippet
Daily used Kotlin Code Snippet
Kotlin without JVM Using Kotlin Native
Kotlin without JVM Using Kotlin Native
How to add GraphView in Android using Graph Library?
How to add GraphView in Android using Graph Library?
ConstraintLayout in Android
ConstraintLayout in Android
How to implement GIFView in Android
How to implement GIFView in Android
Android Instant Run - How it works?
Android Instant Run - How it works?
Use Springy Facebook Rebound?
Use Springy Facebook Rebound?
Add Pull To Make Soup animation in Android
Add Pull To Make Soup animation in Android
Use PreviewSeekBar for Android Video App
Use PreviewSeekBar for Android Video App
KOIN – Functional Kotlin dependency injection framework
KOIN – Functional Kotlin dependency injection framework
Lottie - How to Convert Adobe After Effects to Kotlin
Lottie - How to Convert Adobe After Effects to Kotlin
Boost Android Development using Top 30 Android Tools
Boost Android Development using Top 30 Android Tools
Add Android Increment ProductView in your project?
Add Android Increment ProductView in your project?
Latest features in Android Studio 3.0 Canary 6
Latest features in Android Studio 3.0 Canary 6
How to use Android Audio Widget Overlay View
How to use Android Audio Widget Overlay View
Crumbling Image SlideView in Android
Crumbling Image SlideView in Android
Tinder like SwipeView in Android
Tinder like SwipeView in Android
Android Test with Kotlin
Android Test with Kotlin
How to use Android FabulousFilter with Floating Action Button
How to use Android FabulousFilter with Floating Action Button
How LastAdapter can remove RecyclerView and ViewHolder?
How LastAdapter can remove RecyclerView and ViewHolder?
Kotlin's 5 best things you probably don’t know
Kotlin's 5 best things you probably don’t know
Google Play like UI with RecyclerView Snapping Example
Google Play like UI with RecyclerView Snapping Example
Kotlin 1.1.2 version launched with 15 features
Kotlin 1.1.2 version launched with 15 features
Kotlin disadvantage - 7 reason why i don't like it
Kotlin disadvantage - 7 reason why i don't like it
Facebook New Stories button for Android using PopupBubble Library
Facebook New Stories button for Android using PopupBubble Library
How to add Infinite Cycle ViewPager in Android Application
How to add Infinite Cycle ViewPager in Android Application
Android Side Menu Animation Library
Android Side Menu Animation Library
Fan Layout Manager Android Animation Library
Fan Layout Manager Android Animation Library
ExpectAnim Android Kotlin Animation Library
ExpectAnim Android Kotlin Animation Library
What is Kotlin Anko? How it make development easier with Kotlin?
What is Kotlin Anko? How it make development easier with Kotlin?
Android SpaceTabLayout Animation Tutorial
Android SpaceTabLayout Animation Tutorial
Deca core Features of mPhone 8 Specification
Deca core Features of mPhone 8 Specification
Android Studio Shortcut key
Android Studio Shortcut key
iPhone 8 would have oLED like display
iPhone 8 would have oLED like display
Make Reddit Like Android App Using Kotlin
Make Reddit Like Android App Using Kotlin
Grand Theft Auto V bonuses and discount for limited time
Grand Theft Auto V bonuses and discount for limited time
Android Vertical Stepper Form Library » Tell Me How - A Place for Technology Geekier
Android Vertical Stepper Form Library » Tell Me How - A Place for Technology Geekier
How to implement and customize android search dialog?
How to implement and customize android search dialog?
Dual Core V/S Quad Core : Which is best?
Dual Core V/S Quad Core : Which is best?
Add multiple Adapter - MultiViewAdapter Android Library » Tell Me How - A Place for Technology Geekier
Add multiple Adapter - MultiViewAdapter Android Library » Tell Me How - A Place for Technology Geekier
Android AdaptiveTableLayout CSV Library » Tell Me How - A Place for Technology Geekier
Android AdaptiveTableLayout CSV Library » Tell Me How - A Place for Technology Geekier
How to Prevent and Remove Ransomware virus
How to Prevent and Remove Ransomware virus
How to deal with Android Cards?
How to deal with Android Cards?
Add Android Swipe to delete using Swiperoo Adapter » Tell Me How - A Place for Technology Geekier
Add Android Swipe to delete using Swiperoo Adapter » Tell Me How - A Place for Technology Geekier
Bubble picker Android Library » Tell Me How - A Place for Technology Geekier
Bubble picker Android Library » Tell Me How - A Place for Technology Geekier
How to Add Wave Sidebar Animation Android » Tell Me How - A Place for Technology Geekier
How to Add Wave Sidebar Animation Android » Tell Me How - A Place for Technology Geekier
Android Spruce Animation Library » Tell Me How - A Place for Technology Geekier
Android Spruce Animation Library » Tell Me How - A Place for Technology Geekier
How to Add Progress Button Android Library
How to Add Progress Button Android Library
How to add Android Photofilter Library : Easy way to editing image » Tell Me How
How to add Android Photofilter Library : Easy way to editing image » Tell Me How
[Comparison]: Apple Siri v/s Google Assistant v/s Microsoft Cortona v/s Amazon Alexa
[Comparison]: Apple Siri v/s Google Assistant v/s Microsoft Cortona v/s Amazon Alexa
Android DebugKit : Easy way to debug Android Apps » Tell Me How - A Place for Technology Geekier
Android DebugKit : Easy way to debug Android Apps » Tell Me How - A Place for Technology Geekier
Add Android FAB option menu with Gooey Effect » Tell Me How - A Place for Technology Geekier
Add Android FAB option menu with Gooey Effect » Tell Me How - A Place for Technology Geekier
Contributors
Contributors
Popular Posts
Popular Posts
Archive
Labels
Labels
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.