Creating AnimatedVectorDrawables on Android requires you to create three xml resources that represents each of the following animated-vector , objectAnimator and vector. The <vector /> is the actual file that represents the vector drawable. The <objectAnimator /> defines the animation to apply to different parts of the vector and the <animated-vector /> is used to link the vector drawable and the animation together.

As an example, to create an animated vector drawable that transforms a play icon to stop icon, the following xml files will be created. The Vector drawable:

Continue reading...

In this blog post, we are going to be talking about the Android Support Annotations Library and why we should care about it.

Version 19.1 of the support library included a new annotations package which contains a number of useful annotations that can be added to your code, to help catch bugs. These annotations will help Android studio to check your code for possible errors and report them to you. As of version 22.2 of the support library, this annotations package has been enriched with an additional 13 annotations.

Continue reading...
Bottom Sheets in Android

Bottom Sheet is a material design component, that was added to design support library in version 23.2. Bottom sheet is a very simple window that displays from the bottom of the screen, and can be used to reveal more content to the user. Examples of bottom sheet can be seen in some of Google’s apps and widgets, such as the Place Picker from the Places API.

In this post, I will be showing how you can use bottom sheets in your apps.

Continue reading...

If you have ever thought of writing your own custom Android library for others to use or extend, and wonder how you could achieve that, then you can join me on this ride. In this post, I will be showing a step by step guide on how to create an Android library. I will also be showing you how to distribute your library through JitPack.

Continue reading...

What are Lambda expressions

Lambda Expressions are one of the most important features added to Java 8. Prior to Lambda Expressions, implementing functional interfaces i.e interfaces with only one abstract method has been done using syntax that may seem cumbersome and unclear. In cases like this, what we are trying to do is pass a functionality as an argument to a method, such as what happens when a button is clicked. Lambda expressions enables you to do just that, in a way that is much more compact and clear. In android for example, lambdas can replace anonymous inner class when providing event listeners.

Syntax of Lambda Expressions

A lambda expression consist of the following:

  • A comma separated list of formal parameters enclosed in parentheses. The data types of the parameters in a lambda expression can be omitted. Also the parenthesis can be omitted if there is only one parameter. For example:
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setOnLongClickListener(v -> System.out.println("Long Click"));
  • The arrow token ->
  • A body which contains a single expression or a statement block. If a single expression is specified, the java runtime evaluates the expression and then return its value. To specify a statement block, enclose statements in curly braces "{}"
Continue reading...