Java Code Examples for com.google.android.material.bottomnavigation.BottomNavigationView#setOnNavigationItemSelectedListener()

The following examples show how to use com.google.android.material.bottomnavigation.BottomNavigationView#setOnNavigationItemSelectedListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BottomNavigationActivity.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(LAYOUT);
  navigationSubject = PublishSubject.create();
  bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
  getActivityComponent().inject(this);
  if (savedInstanceState != null) {
    bottomNavigationNavigator.setBottomNavigationItems(
        savedInstanceState.getIntegerArrayList(ITEMS_LIST_KEY));
  }
  bottomNavigationView.setOnNavigationItemSelectedListener(item -> {
    navigationSubject.onNext(item.getItemId());
    return true;
  });
  animationup = AnimationUtils.loadAnimation(this, R.anim.slide_up);
  animationdown = AnimationUtils.loadAnimation(this, R.anim.slide_down);
  toggleBottomNavigation(); //Here because of the SettingsFragment that doesn't extend the BaseFragment
}
 
Example 2
Source File: FriendsFragment.java    From Hify with MIT License 6 votes vote down vote up
@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

   fab=view.findViewById(R.id.searchFab);
   fab.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
           gotoSearch();
       }
   });

    BottomNavigationView bottomNavigationView=view.findViewById(R.id.bottom_nav);
    if(getArguments()!=null){
        bottomNavigationView.setSelectedItemId(R.id.action_view_request);
       loadFragment(new FriendRequests());
   }else {
       loadFragment(new Friends());
   }
    bottomNavigationView.setOnNavigationItemSelectedListener(this);
    bottomNavigationView.setOnNavigationItemReselectedListener(this);


}
 
Example 3
Source File: MoviesActivity.java    From PopularMovies with MIT License 6 votes vote down vote up
private void setupBottomNavigation() {
    BottomNavigationView bottomNav = findViewById(R.id.bottom_navigation);
    bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case R.id.action_discover:
                    ActivityUtils.replaceFragmentInActivity(
                            getSupportFragmentManager(), DiscoverMoviesFragment.newInstance(),
                            R.id.fragment_container);
                    return true;
                case R.id.action_favorites:
                    ActivityUtils.replaceFragmentInActivity(
                            getSupportFragmentManager(), FavoritesFragment.newInstance(),
                            R.id.fragment_container);
                    return true;
            }
            return false;
        }
    });
}
 
Example 4
Source File: HomeActivity.java    From zap-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //NFC
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    mInputMethodManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
    mHandler = new Handler();

    mUnlockDialog = buildUnlockDialog();

    // Register observer to detect if app goes to background
    ProcessLifecycleOwner.get().getLifecycle().addObserver(this);

    // Set wallet fragment as beginning fragment
    mFt = getSupportFragmentManager().beginTransaction();
    mCurrentFragment = new WalletFragment();
    mFt.replace(R.id.mainContent, mCurrentFragment);
    mFt.commit();

    // Setup Listener
    BottomNavigationView navigation = findViewById(R.id.mainNavigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
 
Example 5
Source File: MainActivity.java    From java-unified-sdk with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  mTextMessage = (TextView) findViewById(R.id.message);
  BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
  navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

}
 
Example 6
Source File: TransitionFadeThroughDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle bundle) {

  replaceFragment(R.id.action_albums);

  BottomNavigationView bottomNavigationView = view.findViewById(R.id.bottomnavigation);
  bottomNavigationView.setOnNavigationItemSelectedListener(
      item -> {
        replaceFragment(item.getItemId());
        return true;
      });
}
 
Example 7
Source File: BaseRecyclerViewActivity.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_recycler_view);
        mFragmentManager = getSupportFragmentManager();
        BottomNavigationView navigation = findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

        initFragments();

        navigation.setSelectedItemId(R.id.navigation_home);
//        navigation.setVisibility(View.GONE);
    }
 
Example 8
Source File: MainActivity.java    From AndroidAll with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
 
Example 9
Source File: MainActivity.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
protected void initView() {
    super.initView();

    AndPermission.with(this)
            .runtime()
            .permission(Permission.WRITE_EXTERNAL_STORAGE)
            .start();

    //检测当前是用的哪个播放器
    Object factory = Utils.getCurrentPlayerFactory();
    if (factory instanceof ExoMediaPlayerFactory) {
        setTitle(getResources().getString(R.string.app_name) + " (ExoPlayer)");
    } else if (factory instanceof IjkPlayerFactory) {
        setTitle(getResources().getString(R.string.app_name) + " (IjkPlayer)");
    } else if (factory instanceof AndroidMediaPlayerFactory) {
        setTitle(getResources().getString(R.string.app_name) + " (MediaPlayer)");
    } else {
        setTitle(getResources().getString(R.string.app_name) + " (unknown)");
    }

    BottomNavigationView bottomNavigationView = findViewById(R.id.nav_view);
    bottomNavigationView.setOnNavigationItemSelectedListener(this);

    mFragments.add(new ApiFragment());
    mFragments.add(new ListFragment());
    mFragments.add(new ExtensionFragment());
    mFragments.add(new PipFragment());

    getSupportFragmentManager().beginTransaction()
            .add(R.id.layout_content, mFragments.get(0))
            .commitAllowingStateLoss();

    mCurrentIndex = 0;
}
 
Example 10
Source File: MainActivity.java    From android-DarkTheme with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationListener);

    if (savedInstanceState == null) {
        showFragment(WelcomeFragment.TAG);
    }
}
 
Example 11
Source File: BottomNavigationViewBindingAdapter.java    From deagle with Apache License 2.0 5 votes vote down vote up
@BindingAdapter(value = {"onNavigationItemSelected", "selectedItemIdAttrChanged" }, requireAll = false)
public static void setOnItemSelectedListener(final BottomNavigationView view, final @Nullable OnNavigationItemSelectedListener listener,
											 final @Nullable InverseBindingListener notifier) {
	if (listener == null && notifier == null) view.setOnNavigationItemSelectedListener(null);
	else view.setOnNavigationItemSelectedListener(new OnNavigationItemSelectedListener() {
		@Override public boolean onNavigationItemSelected(final MenuItem item) {
			if (view.getSelectedItemId() == item.getItemId()) return true;
			if (notifier != null) view.post(new Runnable() { @Override public void run() {
				notifier.onChange();			// Async to avoid infinite loop
			}});
			return listener == null || listener.onNavigationItemSelected(item);
		}
	});
}
 
Example 12
Source File: MainActivity.java    From memorize with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    setFragment(WordsFragment.newInstance());
}
 
Example 13
Source File: Forum.java    From Hify with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    BottomNavigationView bottomNavigationView=view.findViewById(R.id.bottom_nav);
    bottomNavigationView.setOnNavigationItemSelectedListener(this);
    bottomNavigationView.setOnNavigationItemReselectedListener(this);

    loadfragment(new AllQuestions());

}
 
Example 14
Source File: Dashboard.java    From Hify with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    BottomNavigationView bottomNavigationView=view.findViewById(R.id.bottom_nav);
    bottomNavigationView.setOnNavigationItemSelectedListener(this);
    bottomNavigationView.setOnNavigationItemReselectedListener(this);

    loadfragment(new Home());
    checkforNotifications();
    checkFriendRequest();

}
 
Example 15
Source File: MainActivity.java    From user-interface-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationListener);

    if (savedInstanceState == null) {
        showFragment(WelcomeFragment.TAG);
    }
}
 
Example 16
Source File: MainActivity.java    From mcumgr-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    // The target must be set before calling super.onCreate(Bundle).
    // Otherwise, Dagger2 will fail to inflate this Activity.
    final BluetoothDevice device = getIntent().getParcelableExtra(EXTRA_DEVICE);
    final String deviceName = device.getName();
    final String deviceAddress = device.getAddress();
    ((Dagger2Application) getApplication()).setTarget(device);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    new ViewModelProvider(this, mViewModelFactory)
            .get(MainViewModel.class);

    // Configure the view.
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(deviceName);
    getSupportActionBar().setSubtitle(deviceAddress);

    final BottomNavigationView navMenu = findViewById(R.id.nav_menu);
    navMenu.setSelectedItemId(R.id.nav_default);
    navMenu.setOnNavigationItemSelectedListener(item -> {
        switch (item.getItemId()) {
            case R.id.nav_default:
                getSupportFragmentManager().beginTransaction()
                        .show(mDeviceFragment).hide(mImageFragment)
                        .hide(mFilesFragment).hide(mLogsStatsFragment)
                        .commit();
                return true;
            case R.id.nav_dfu:
                getSupportFragmentManager().beginTransaction()
                        .hide(mDeviceFragment).show(mImageFragment)
                        .hide(mFilesFragment).hide(mLogsStatsFragment)
                        .commit();
                return true;
            case R.id.nav_fs:
                getSupportFragmentManager().beginTransaction()
                        .hide(mDeviceFragment).hide(mImageFragment)
                        .show(mFilesFragment).hide(mLogsStatsFragment)
                        .commit();
                return true;
            case R.id.nav_stats:
                getSupportFragmentManager().beginTransaction()
                        .hide(mDeviceFragment).hide(mImageFragment)
                        .hide(mFilesFragment).show(mLogsStatsFragment)
                        .commit();
                return true;
        }
        return false;
    });

    // Initialize fragments.
    if (savedInstanceState == null) {
        mDeviceFragment = new DeviceFragment();
        mImageFragment = new ImageFragment();
        mFilesFragment = new FilesFragment();
        mLogsStatsFragment = new LogsStatsFragment();

        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, mDeviceFragment, "device")
                .add(R.id.container, mImageFragment, "image")
                .add(R.id.container, mFilesFragment, "fs")
                .add(R.id.container, mLogsStatsFragment, "logs")
                // Initially, show the Device fragment and hide others.
                .hide(mImageFragment).hide(mFilesFragment).hide(mLogsStatsFragment)
                .commit();
    } else {
        mDeviceFragment = getSupportFragmentManager().findFragmentByTag("device");
        mImageFragment = getSupportFragmentManager().findFragmentByTag("image");
        mFilesFragment = getSupportFragmentManager().findFragmentByTag("fs");
        mLogsStatsFragment = getSupportFragmentManager().findFragmentByTag("logs");
    }
}
 
Example 17
Source File: MainActivity.java    From Clock-view with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    clockFragment = new ClockFragment();
    stopwatchFragment = new StopwatchFragment();
    timeCounterFragment = new TimeCounterFragment();

    loadFragment(clockFragment);
    toolbar = getSupportActionBar();


    BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
    bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            switch (menuItem.getItemId()) {

                case R.id.clock:
                    loadFragment(clockFragment);
                    toolbar.setTitle(R.string.clock);
                    return true;

                case R.id.stopwatch:
                    loadFragment(stopwatchFragment);
                    toolbar.setTitle(R.string.stopwatch);
                    return true;

                case R.id.time_counter:
                    loadFragment(timeCounterFragment);
                    toolbar.setTitle(R.string.time_counter);
                    return true;
            }

            return false;
        }
    });

    toolbar.setTitle(R.string.clock);
}
 
Example 18
Source File: HistoryDetailsActivity.java    From SecScanQR with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    generalHandler = new GeneralHandler(this);
    generalHandler.loadTheme();
    setContentView(R.layout.activity_history_details);
    tvCode = (TextView) findViewById(R.id.tvTxtqrcodeHistory);
    tvFormat = (TextView) findViewById(R.id.tvFormatHistory);
    codeImage = (ImageView) findViewById(R.id.resultImageHistory);
    codeImage.setClickable(true);

    action_navigation = (BottomNavigationView) findViewById(R.id.history_action_navigation);
    action_navigation.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
    action_navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    historyDatabaseHelper = new DatabaseHelper(this);

    //Get the extra information from the history listview. and set the text in the textview eqaul to code
    Intent receivedIntent = getIntent();
    selectedCode = receivedIntent.getStringExtra(EXTRA_INFORMATION);
    tvCode.setText(selectedCode);
    selectedFormat = receivedIntent.getStringExtra(EXTRA_FORMAT);
    tvFormat.setText(selectedFormat);
    showQrImage();

    if(selectedCode.contains("BEGIN:VCARD") & selectedCode.contains("END:VCARD")){
        action_navigation.getMenu().removeItem(R.id.history_action_navigation_openInWeb);
    } else {
        action_navigation.getMenu().removeItem(R.id.history_action_navigation_createContact);
    }

    codeImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(HistoryDetailsActivity.this , GeneratorResultActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("CODE", selectedCode);
            int formatID = generalHandler.StringToBarcodeId(selectedFormat);
            bundle.putInt("FORMAT", formatID);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    });
}
 
Example 19
Source File: BottomNavigationDemoFragment.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void setBottomNavListeners(OnNavigationItemSelectedListener listener) {
  for (BottomNavigationView bn : bottomNavigationViews) {
    bn.setOnNavigationItemSelectedListener(listener);
  }
}
 
Example 20
Source File: FlashMessage.java    From Hify with MIT License 3 votes vote down vote up
@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    loadFragment(new SendMessage());

    BottomNavigationView bottomNavigationView=view.findViewById(R.id.bottom_nav);
    bottomNavigationView.setOnNavigationItemSelectedListener(this);
    bottomNavigationView.setOnNavigationItemReselectedListener(this);


}