Search in sources :

Example 1 with ActivityMainBinding

use of com.google.firebase.quickstart.database.databinding.ActivityMainBinding in project quickstart-android by firebase.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    setSupportActionBar(binding.toolbar);
    fab = binding.fab;
    navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    navController.setGraph(R.navigation.nav_graph_java);
    navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {

        @Override
        public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
            if (destination.getId() == R.id.MainFragment) {
                fab.setVisibility(View.VISIBLE);
                fab.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        navController.navigate(R.id.action_MainFragment_to_NewPostFragment);
                    }
                });
            } else {
                fab.setVisibility(View.GONE);
            }
        }
    });
}
Also used : NavDestination(androidx.navigation.NavDestination) Bundle(android.os.Bundle) NavController(androidx.navigation.NavController) ActivityMainBinding(com.google.firebase.quickstart.database.databinding.ActivityMainBinding) View(android.view.View)

Aggregations

Bundle (android.os.Bundle)1 View (android.view.View)1 NavController (androidx.navigation.NavController)1 NavDestination (androidx.navigation.NavDestination)1 ActivityMainBinding (com.google.firebase.quickstart.database.databinding.ActivityMainBinding)1