Navigation Drawer item background colour for selected item

To solve this problem: 1- You don’t need android:listSelector under your ListView. 2- Open (or Create) styles.xml under (res/values). <!– Base application theme. –> <style name=”AppTheme” parent=”Theme.AppCompat.Light.DarkActionBar”> <!– Customize your theme here. –> <item name=”android:activatedBackgroundIndicator”>@drawable/drawer_list_selector</item> </style> 3- Under res/drawable folder create drawer_list_selector.xml file <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_pressed=”true” android:drawable=”@drawable/light_gray_color” /> <item android:state_activated=”true” android:drawable=”@drawable/red_color” /> <item android:drawable=”@android:color/transparent” … Read more

Android Jetpack Navigation, BottomNavigationView with Youtube or Instagram like proper back navigation (fragment back stack)?

You don’t really need a ViewPager to work with BottomNavigation and the new Navigation architecture component. I have been working in a sample app that uses exactly the two, see here. The basic concept is this, you have the main activity that will host the BottomNavigationView and that is the Navigation host for your navigation … Read more

Android Navigation Architecture Component – Get current visible fragment

I managed to discover a way for now and it is as follows: NavHostFragment navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host); navHostFragment.getChildFragmentManager().getFragments().get(0); In case of course you know it is the first fragment. I am still investigating a way without this. I agree it is not the best way but that should be something for now.

FragmentContainerView using findNavController

As per this issue, when using FragmentContainerView, you need to find the NavController using findFragmentById() rather than using findNavController() when in onCreate(): val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment val navController = navHostFragment.navController This is because findNavController(R.id.nav_host_fragment) relies on the Fragment’s View to already be created which isn’t the case when using FragmentContainerView (as it uses … Read more

IllegalArgumentException: navigation destination xxx is unknown to this NavController

In my case, if the user clicks the same view twice very very quickly, this crash will occur. So you need to implement some sort of logic to prevent multiple quick clicks… Which is very annoying, but it appears to be necessary. You can read up more on preventing this here: Android Preventing Double Click … Read more

Action bar navigation modes are deprecated in Android L

The new Android Design Support Library adds TabLayout, providing a tab implementation that matches the material design guidelines for tabs. A complete walkthrough of how to implement Tabs and ViewPager can be found in this video Now deprecated: The PagerTabStrip is part of the support library (and has been for some time) and serves as … Read more

How to change the status bar color in Android?

Android 5.0 Lollipop introduced Material Design theme which automatically colors the status bar based on the colorPrimaryDark value of the theme. Note by realdognose: with Material Design library it will be colorPrimaryVariant This is supported on device pre-lollipop thanks to the library support-v7-appcompat starting from version 21. Blogpost about support appcompat v21 from Chris Banes … Read more