How to make bottom navigation show menu items with icon and text except center item menu show only icon? [closed]

Try below code: XML file: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical”> <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_gravity=”top” android:background=”@color/gray” android:foregroundGravity=”top” android:gravity=”top”> </android.support.v7.widget.Toolbar> <FrameLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:layout_weight=”1″> <FrameLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/fragment_container” android:layout_width=”match_parent” android:layout_height=”match_parent” /> </FrameLayout> <LinearLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:orientation=”horizontal”> <android.support.design.widget.BottomNavigationView android:id=”@+id/bottomnav” android:layout_width=”0dp” android:layout_height=”56dp” android:layout_weight=”1″ android:background=”null” app:itemIconTint=”@color/green” app:itemTextColor=”@color/green” app:menu=”@menu/main”> </android.support.design.widget.BottomNavigationView> <ImageView android:layout_width=”0dp” android:layout_height=”56dp” android:layout_weight=”0.5″ android:src=”https://stackoverflow.com/questions/44342530/@drawable/camera” /> <android.support.design.widget.BottomNavigationView … Read more

Is it possible to set startDestination conditionally using Android Navigation Architecture Component(Android Jetpack)?

Finally, I got a solution to my query… Put below code in onCreate() method of Activity. Kotlin code val navHostFragment = (supportFragmentManager.findFragmentById(R.id.home_nav_fragment) as NavHostFragment) val inflater = navHostFragment.navController.navInflater val graph = inflater.inflate(R.navigation.nav_main) //graph.addArgument(“argument”, NavArgument) graph.setStartDestination(R.id.fragment1) //or //graph.setStartDestination(R.id.fragment2) navHostFragment.navController.graph = graph Java code NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.home_nav_fragment); // Hostfragment NavInflater inflater = navHostFragment.getNavController().getNavInflater(); NavGraph graph … Read more

How to change start destination of a navigation graph programmatically?

UPDATE: When you have nav graph like this: <fragment android:id=”@+id/firstFragment” android:name=”com.appname.package.FirstFragment” > <action android:id=”@+id/action_firstFragment_to_secondFragment” app:destination=”@id/secondFragment” /> </fragment> <fragment android:id=”@+id/secondFragment” android:name=”com.appname.package.SecondFragment”/> And you want to navigate to the second fragment and make it root of your graph, specify the next NavOptions: NavOptions navOptions = new NavOptions.Builder() .setPopUpTo(R.id.firstFragment, true) .build(); And use them for the navigation: Navigation.findNavController(view).navigate(R.id.action_firstFragment_to_secondFragment, … Read more

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 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.

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

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