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



  1.  

    0

    Add a comment

  2. Easy Steps to Add 301 Redirects to WordPress » Tell Me How - A Place for Technology Geekier: Before we try to learn how to add 301 redirects to WordPress, we need to understand what they really are. If you run your own website, it is a must to understand the ‘when’ and ‘how’ of using these. If you are ignorant on the topic, you could be losing a lot of organic traffic …
    0

    Add a comment

  3. Is Purefit Keto Beneficial For Weight Loss? » Tell Me How - A Place for Technology Geekier: The ketogenic diet is probably something that everyone interested in physical fitness might have heard about. In this diet plan, you eat lots of fat so that your body to burn even more fat. Purefit is a supplement that helps your body to do that. When our body is in a state of normal metabolism …
    0

    Add a comment

  4. The Best SEO Practices for Blogging » Tell Me How - A Place for Technology Geekier: How can SEO help your blog and vice versa? Today, we will give you some information about the best SEO Practices for Blogging.
    0

    Add a comment

  5. json2view : Some important properties and types » Tell Me How - A Place for Technology Geekier: Here we see some important properties and types of json2view library which you can use in your applications. Just dive and enjoy the tutorials and code.
    0

    Add a comment

  6. Yes You Can! How Millennials Can Actually Afford a House » Tell Me How - A Place for Technology Geekier: The consensus across the world is that Millennials can’t afford to buy houses. Sadly, this means that a lot of them have stopped trying. To be clear, Millennials can afford to buy a house in a lot of cases. They are, however, facing more barriers and challenges in homeownership than any generation has ever faced.  …
    0

    Add a comment

  7. THE BEST GADGETS FOR STUDYING OF 2020 
    0

    Add a comment

  8. However, along with this news, how are JDK builds available? Will they be free or paid? Before answering this, it's important to understand what a "valid" JDK for distribution actually means. In practical terms, there is only one set of source code for the JDK. 

    JDK Alternatives for Production
    JDK Alternatives for Production



    The source code is hosted here. Anyone can pick up this source code, produce a build, and post it to a URL. However, there is a separate certification process that must be used to ensure that construction is valid. Certification is performed by the Java Community Process (JCP), which provides a Technology Compatibility Kit (TCK). 
    If an organization produces an OpenJDK build that complies with the entirely TCK, this build may be described as "compatible with Java SE".
    Note that the build cannot be called "Java SE" without the vendor obtaining a commercial license from Oracle. For example, AdoptOpenJDK builds that pass the TCK are not "Java SE," but "Java SE compliant" or "Java SE compliant." Also, note that certification is currently on a trust basis — results are not sent to JCP/Oracle for verification and cannot be made public. In short, the OpenJDK + Vendor process transforms a source base into several different builds.

    Figure 1: OpenJDK source code transformed into builds (per Vendor)


    Without further ado, check out the following JDKs that are ready to download: Alternatives of Premium JDK





    0

    Add a comment

  9. Animated Recycler View is a library that allows you to animate a recycler view in your project like Google does it in its Google Play Store. Only the first visible items are animated there and you will see no animation when the recycler view scrolls up.
    Animated Recycler View - Transition Page Recycler with layout animations
    Animated Recycler View – Transition Page Recycler with layout animations

    Reasons to use it

    This library solves several problems:
    1. It works stably fast and without jerks.
    2. It doesn’t need to utilize the adapter to animate items when they appear for the first time.

    Why Animated Recycler View is special for you?

    While working on a project, most of time we need animation similar to the one used in the Google Play Store but didn’t find any appropriate library on Internet/ Github/ StackOverflow that could help us with this task. 
    Source: How to Transition Page Recycler using Animated Recycler View? 
    0

    Add a comment



  10. There are so many ways to make mobile apps ranging from direct platform specific development (using Java and Kotlin for Android, and ObjC and Swift for iOS), there’s React Native from Facebook, Electrode Native from Walmart, the Ionic framework, Unity for certain types of apps, and the flutter.io framework which was just released by Google.



    Ever wondered how these libraries and frameworks affect the size of your app? Let’s analyze some apk files for apps written in some of these ways. The apps are very basic, containing just a title at the top and a text at the center of the screen.

    This will show, for a bare minimum app what these frameworks need to package along with the apk for it to be able to run.

    • For this test I created four different versions of the app, one in each of JavaKotlinReact Nativeand Flutter. (Android API 27)
    • The apks were then published for release type using Android Studio for Java and Kotlin and using the cli for React Native and Flutter.
    • Default proguard configuration was used.
    • The apks were analyzed using the Analyze APK feature in Android Studio.
    Source: Which Language is Good for Android by Analyze APK sizes?
    0

    Add a comment

Contributors
Contributors
Popular Posts
Popular Posts
Archive
Labels
Labels
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.