Category: Tips

  • Implement Parcelable to Bundle your POJOs

    Every Android Developer is familiar with passing data via a  Bundle or Intent.

    In doing so, you would have wanted to pass your entire POJO (Plain Old Java Object) class,or List<Bean>. But Intent or Bundle don’t allow that right off the bat. The key lies in your Beans implementing Parcelable. (more…)

  • Swipe to Dismiss for RecyclerView with ItemTouchHelper

    A hidden gem in Android Support Library, is the built in Swipe to Dismiss functionality.

    Using the ItemTouchHelper class, we can add this to a RecyclerView.

    1. Create a SimpleCallback
    ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
    
            @Override
            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
                return false;
            }
    
            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
                //Remove swiped item from list and notify the RecyclerView
            }
        };

    The onSwiped() method is where you should remove the item. Don’t forget to notify your RecyclerView!
    2. Finally, create an ItemTouchHelper instance and attach it to RecyclerView.

    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);

     

  • Using Vector Assets for Icons in Android Studio 1.4

    Since Android Studio 1.4, we can use Vector Assets which was earlier restricted to Lollipop alone. This is more efficient since one drawable which requires multiple instances saved in different density folders will now be replaced by just ONE single vector asset inside res/drawable/

    (more…)

  • Overlap a Transparent Status Bar

    There’s a lot going on about making your Status Bar transparent for your Activities. But most of the time, its easier said than done and if android:fitsSystemWindows = "true" doesn’t work for you, then there is another way.

    (more…)

  • Material Design Android Ripple Effect

    Here’s on how to add a neat Ripple effect for your UI components. I’ll take a button for this.

    (more…)

  • Tint Icons in Android for pre Lollipop

    Tint icons were first seen on Android Lollipop. The same can now be done on previous versions too with the help of Support Libraries.

    (more…)