Skip to main content

Posts

Countdown Timer

  we will learn, how to build a simple countdown timer, which shows the remaining time in minutes and seconds. It will have a start/pause button and a reset button which is only visible, if the timer is not running. For this, we will use the CountDownTimer interface and override the onTick and onFinish methods. We will set it’s time in milliseconds and format those milliseconds to minutes and seconds using the String.format method. Start a new Empty Project -> Add these lines of codes in activity_main.xml file:- <? xml version ="1.0" encoding ="utf-8" ?> < RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" android :layout_height ="match_parent" tools :context =".MainActivity" > < TextView androi...

Circular Determinate ProgressBar with Background and Text

we will learn how to create a circular progress bar in Android Studio that displays the current progress value and has a gray background color. I will also show you how you can customize this progress bar further and add things like a color gradient effect. After successful Empty activity creation add these lines of code in the files:- Add a circle.xml file in Drawable folder and add these lines of codes:- <? xml version ="1.0" encoding ="utf-8" ?> < layer-list xmlns: android ="http://schemas.android.com/apk/res/android" > < item > < shape android :shape ="ring" android :thicknessRatio ="16" android :useLevel ="false" > < solid android :color ="#DDD" /> </ shape > </ item > < item > < rotate android :fromDegrees ="270" android :toDegrees ="270...

BottomNavigationView

In this tutorial we will learn, how to add a bottom navigation to your activity and use it to switch between different fragments. We will fill our BottomNavigationView with 3 menu items and then check which item was selected with the OnNavigationItemSelectedListener interface and a switch statement. We will then create the appropriate fragment and display it in a FrameLayout with help of the getSupportFragmentManager, beginTransaction and replace methods. Link & Dependencies:- developer.android.com/topic/libraries/support-library/packages.html#design Add a directory in res folder and name it as menu. After adding menu folder in res folder add a xml file and name it bottom_navigation.xml. <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/nav_home" android:icon="@drawable/ic_home_black_24dp" android:titl...

GSON - Simple Serialization + Deserialization

GSON library, which is provided by Google and makes the process of turning Java objects into their  JSON representation (serialization) and JSONs into Java objects (deserialization) very easy. we are going to create a simple Java class, create an object of it, turn it into a JSON and then turn that JSON back into the java object. We will also learn how to use the @SerializedName annotation to use different keys and variable names. Links and dependencies:-   github.com/google/gson In Employee.java class file add these lines of codes:-   Employee.java import com.google.gson.annotations.SerializedName ; public class Employee { @SerializedName ( "first_name" ) private String mFirstName; @SerializedName ( "age" ) private int mAge; @SerializedName ( "mail" ) private String mMail; public Employee ( String firstName, int age, String mail ) { mFirstName = firstName; mAge = age; mMail = mail; } } ...