android.support.design.widget.BottomNavigationView Java Examples

The following examples show how to use android.support.design.widget.BottomNavigationView. 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: MainActivity.java    From MBEStyle with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    StatusBarUtils.setColor(this, ContextCompat.getColor(this, R.color.colorPrimary));

    BottomNavigationView bottomView = (BottomNavigationView) findViewById(R.id.bottom_bar);
    bottomView.setOnNavigationItemSelectedListener(this);
    setBottomIconOriColor(bottomView);

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

    mFragments = Arrays.asList(
            new IconFragment(),
            new ApplyFragment(),
            new RequestFragment(),
            new AboutFragment());

    mFragmentManager = getFragmentManager();

    switchFragment(0);
    handleToolbarElevation(0);
}
 
Example #2
Source File: StyleActivity.java    From BottomNavigationViewEx with MIT License 6 votes vote down vote up
private void initCenterIconOnly() {
    disableAllAnimation(bind.bnveCenterIconOnly);
    int centerPosition = 2;
    // attention: you must ensure the center menu item title is empty
    // make icon bigger at centerPosition
    bind.bnveCenterIconOnly.setIconSizeAt(centerPosition, 48, 48);
    bind.bnveCenterIconOnly.setItemBackground(centerPosition, R.color.colorGreen);
    bind.bnveCenterIconOnly.setIconTintList(centerPosition,
            getResources().getColorStateList(R.color.selector_item_gray_color));
    bind.bnveCenterIconOnly.setIconMarginTop(centerPosition, BottomNavigationViewEx.dp2px(this, 4));
    // you could set a listener for bnve. and return false when click the center item so that it won't be checked.
    bind.bnveCenterIconOnly.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            if (item.getItemId() == R.id.menu_add) {
                Toast.makeText(StyleActivity.this, "add", Toast.LENGTH_SHORT).show();
                return false;
            }
            return true;
        }
    });
}
 
Example #3
Source File: AppListViewModel.java    From island with Apache License 2.0 6 votes vote down vote up
public void attach(final Context context, final Menu actions, final BottomNavigationView tabs, final @Nullable Bundle saved_state) {
	mAppListProvider = IslandAppListProvider.getInstance(context);
	mDeviceOwner = new DevicePolicies(context).isActiveDeviceOwner();
	mActions = actions;
	mFilterShared = IslandAppListProvider.excludeSelf(context).and(AppInfo::isInstalled);
	mPrimaryFilter.observeForever(filter -> updateActiveFilters());

	if (! Filter.Island.available()) {		// Island is unavailable
		tabs.getMenu().removeItem(R.id.tab_island);
		tabs.setSelectedItemId(R.id.tab_mainland);
		mPrimaryFilter.setValue(Filter.Mainland);
		setTitle(context, tabs.getMenu().findItem(R.id.tab_mainland));
	} else {
		final int ordinal = Optional.ofNullable(saved_state).map(s -> s.getInt(STATE_KEY_FILTER_PRIMARY_CHOICE)).orElse(Filter.Island.ordinal()/* default */);
		final Filter primary_filter = Filter.values()[ordinal];
		tabs.setSelectedItemId(primary_filter == Filter.Mainland ? R.id.tab_mainland : R.id.tab_island);
		mPrimaryFilter.setValue(primary_filter);
		setTitle(context, tabs.getMenu().findItem(tabs.getSelectedItemId()));
	}
	mSelection.observeForever(selection -> {
		final Interpolator interpolator = new AccelerateDecelerateInterpolator();
		if (selection != null) tabs.animate().alpha(0).translationZ(-10).scaleX(0.95f).scaleY(0.95f).setDuration(200).setInterpolator(interpolator);
		else tabs.animate().alpha(1).translationZ(0).scaleX(1).scaleY(1).setDuration(200).setInterpolator(interpolator);
	});
}
 
Example #4
Source File: MainActivity.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
private void initBottomNavView() {
    mMainBinding.bottomNavView.setOnNavigationItemSelectedListener(
            new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    switch (item.getItemId()) {
                        case R.id.bottom_nav_item_home:
                            loadHomeFragment();
                            break;
                        case R.id.bottom_nav_item_orders:
                            loadOrdersFragment();
                            break;
                        case R.id.bottom_nav_item_hold:
                            loadHoldFragment();
                            break;
                        case R.id.bottom_nav_item_more:
                            loadMoreFragment();
                            break;
                    }
                    return true;
                }
            });
    removeBottomNavShiftMode();
}
 
Example #5
Source File: SkinMaterialBottomNavigationView.java    From Android-skin-support with MIT License 6 votes vote down vote up
public SkinMaterialBottomNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomNavigationView, defStyleAttr,
            R.style.Widget_Design_BottomNavigationView);

    if (a.hasValue(R.styleable.BottomNavigationView_itemIconTint)) {
        mIconTintResId = a.getResourceId(R.styleable.BottomNavigationView_itemIconTint, INVALID_ID);
    } else {
        mDefaultTintResId = resolveColorPrimary();
    }
    if (a.hasValue(R.styleable.BottomNavigationView_itemTextColor)) {
        mTextColorResId = a.getResourceId(R.styleable.BottomNavigationView_itemTextColor, INVALID_ID);
    } else {
        mDefaultTintResId = resolveColorPrimary();
    }
    a.recycle();
    applyItemIconTintResource();
    applyItemTextColorResource();
}
 
Example #6
Source File: MainActivity.java    From Cashew with Apache License 2.0 6 votes vote down vote up
@Override
public void initView(Bundle savedInstanceState) {
    SwipeBackHelper.getCurrentPage(this)
            .setSwipeBackEnable(false);
    SwipeBackHelper.getCurrentPage(this).setDisallowInterceptTouchEvent(true);
    getBinding().bnve.enableAnimation(false);
    getBinding().bnve.enableShiftingMode(false);
    getBinding().bnve.enableItemShiftingMode(false);
    List<Fragment> fragments = new ArrayList<>();
    fragments.add(new DailyFragment());
    fragments.add(new ClassifyFragment());
    fragments.add(new GirlFragment());
    getBinding().viewpagerMain.setOffscreenPageLimit(fragments.size());
    NoTouchNoAnimPagerAdapter noTouchNoAnimPagerAdapter = new NoTouchNoAnimPagerAdapter(getSupportFragmentManager(), fragments);
    getBinding().viewpagerMain.setAdapter(noTouchNoAnimPagerAdapter);
    setFrag(R.id.b_i_day);
    getBinding().bnve.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            setFrag(item.getItemId());
            return true;
        }
    });
}
 
Example #7
Source File: BrowsingActivityNavigationController.java    From IslamicLibraryAndroid with GNU General Public License v3.0 6 votes vote down vote up
public static BrowsingActivityNavigationController create(int paneNumber,
                                                          int oldPanNumbers,
                                                          FragmentManager fragmentManager,
                                                          boolean fromRotation,
                                                          BrowsingActivity browsingActivity,
                                                          BottomNavigationView bottomNavigationView,
                                                          BrowsingActivityControllerListener listener) {
    switch (paneNumber) {
        case 1: {
            if (oldPanNumbers <= 1)
                return new BrowsingActivityNavigationControllerSinglePaneAlways(oldPanNumbers, fragmentManager, fromRotation, browsingActivity, bottomNavigationView, listener);
            else
                return new BrowsingActivityNavigationControllerSinglePane(oldPanNumbers, fragmentManager, fromRotation, browsingActivity, bottomNavigationView, listener);
        }
        case 2:
            return new BrowsingActivityNavigationControllerDualPan(oldPanNumbers, fragmentManager, fromRotation, browsingActivity, bottomNavigationView, listener);
        case 3:
            return new BrowsingActivityNavigationControllerTriplePan(oldPanNumbers, fragmentManager, fromRotation, browsingActivity, bottomNavigationView, listener);
        default:
            return null;
    }
}
 
Example #8
Source File: MainActivity.java    From MBEStyle with GNU General Public License v3.0 6 votes vote down vote up
private void setBottomIconOriColor(BottomNavigationView bottomView) {
    try {
        Field mMenuViewField = BottomNavigationView.class.getDeclaredField("mMenuView");
        mMenuViewField.setAccessible(true);
        BottomNavigationMenuView mMenuView = (BottomNavigationMenuView) mMenuViewField.get(bottomView);

        Field mButtonsField = BottomNavigationMenuView.class.getDeclaredField("mButtons");
        mButtonsField.setAccessible(true);
        BottomNavigationItemView[] mButtons = (BottomNavigationItemView[]) mButtonsField.get(mMenuView);

        Field mIconField = BottomNavigationItemView.class.getDeclaredField("mIcon");
        mIconField.setAccessible(true);

        for (BottomNavigationItemView item : mButtons) {
            ImageView mIcon = (ImageView) mIconField.get(item);
            mIcon.setImageTintList(null);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #9
Source File: MainActivity.java    From FragmentStateManager with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    FrameLayout content = findViewById(R.id.content);
    fragmentStateManager = new FragmentStateManager(content, getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            // A switch case should be here for showing different fragments for
            // different positions which is omitted for simplicity
            return new HolderFragment();
        }
    };

    if (savedInstanceState == null) {
        fragmentStateManager.changeFragment(0);
    }

    BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    navigation.setOnNavigationItemReselectedListener(mOnNavigationItemReselectedListener);
}
 
Example #10
Source File: MainActivity.java    From owt-client-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_main);

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

    loginFragment = new LoginFragment();
    switchFragment(loginFragment);

    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

    initP2PClient();
}
 
Example #11
Source File: MainActivity.java    From star-zone-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setTitle("星座空间");
    setTitleMode(TitleBar.MODE_TITLE);

    fManager = getSupportFragmentManager();
    //
    setChioceItem(0);
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    BottomNavigationViewHelper.disableShiftMode(navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

    initView();
    requestWritePermission();
}
 
Example #12
Source File: StyleActivity.java    From BottomNavigationViewEx with MIT License 5 votes vote down vote up
/**
 * There is no idea to set no check item first time.
 * But we can let user think it is unchecked first time by control the color
 */
private void initUncheckedFirstTime() {
    disableAllAnimation(bind.bnveUncheckedFirstTime);
    // use the unchecked color for first item
    bind.bnveUncheckedFirstTime.setIconTintList(0, getResources()
            .getColorStateList(R.color.colorGray));
    bind.bnveUncheckedFirstTime.setTextTintList(0, getResources()
            .getColorStateList(R.color.colorGray));
    bind.bnveUncheckedFirstTime.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        private boolean firstClick = true;
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            // restore the color when click
            if (firstClick) {
                int position = bind.bnveUncheckedFirstTime.getMenuItemPosition(item);
                if (0 == position) {
                    firstClick = false;
                    bind.bnveUncheckedFirstTime.setIconTintList(0, getResources()
                            .getColorStateList(R.color.selector_item_primary_color));
                    bind.bnveUncheckedFirstTime.setTextTintList(0, getResources()
                            .getColorStateList(R.color.selector_item_primary_color));
                }
            }
            // do other
            return true;
        }
    });
}
 
Example #13
Source File: BottomActivity.java    From Cybernet-VPN with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bottom);

    mTextMessage = (TextView) findViewById(R.id.message);
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
 
Example #14
Source File: BottomNavigationActivity.java    From AndroidModulePattern with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bottom_navigation);
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    initViewPager();
}
 
Example #15
Source File: BrowsingActivityNavigationController.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
BrowsingActivityNavigationController(int oldPanNumbers, FragmentManager fragmentManager, boolean fromRotation, BrowsingActivity activity, BottomNavigationView bottomNavigationView, BrowsingActivityControllerListener listener) {
    this.oldPanNumbers = oldPanNumbers;
    this.fragmentManager = fragmentManager;
    this.fromRotation = fromRotation;
    this.activity = activity;
    this.bottomNavigationView = bottomNavigationView;
    this.listener = listener;
}
 
Example #16
Source File: BottomNavigationViewActivity.java    From AndroidDesignWidgetsSample with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bottom_navigation_view);
    ButterKnife.bind(this);
    setSupportActionBar(toolbar);
    BottomNavigationViewHelper.removeShiftMode(bottomNavigationView);
    bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            return true;
        }
    });
}
 
Example #17
Source File: MainActivity.java    From canvas 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);

    //canvasView = findViewById(R.id.canvasView);
    parentView = findViewById(R.id.parentView);
    canvasView = new CanvasView(MainActivity.this);
    parentView.addView(canvasView);

    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
 
Example #18
Source File: BottomNavigationViewHelper.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
public static void disableShiftMode(Context context, BottomNavigationView view) {
    int color = ATHUtil.resolveColor(context, android.R.attr.textColorSecondary);
    setItemIconColors(view, color, ThemeStore.accentColor(context));
    setItemTextColors(view, color, ThemeStore.accentColor(context));

    BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);

    try {
        Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
        shiftingMode.setAccessible(true);
        shiftingMode.setBoolean(menuView, false);
        shiftingMode.setAccessible(false);
        for (int i = 0; i < menuView.getChildCount(); i++) {
            BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);


             /*TextView smallText = (TextView) item.findViewById(R.id.smallLabel);
            smallText.setVisibility(View.GONE);
            TextView largeLabel = (TextView) item.findViewById(R.id.largeLabel);
            largeLabel.setVisibility(View.GONE);

            AppCompatImageView icon = (AppCompatImageView) item.getChildAt(0);

            FrameLayout.LayoutParams params = (BottomNavigationView.LayoutParams) icon.getLayoutParams();
            params.gravity = Gravity.CENTER;*/

            //noinspection RestrictedApi
            item.setShiftingMode(false);
            // set once again checked value, so view will be updated
            //noinspection RestrictedApi
            item.setChecked(item.getItemData().isChecked());
        }
    } catch (NoSuchFieldException | IllegalAccessException ignored) {
        ignored.printStackTrace();
    }
}
 
Example #19
Source File: DemoActivity.java    From JIMU with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo);

    mTextMessage = (TextView) findViewById(R.id.message);
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
 
Example #20
Source File: BottomNavigationViewActivity.java    From twoh-android-material-design with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_bottom_nav_view);

    bottomNavigationView = (BottomNavigationView) findViewById(R.id.btm_nav);
    bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {

            switch (item.getItemId()){
                case R.id.action_home :
                    Toast.makeText(BottomNavigationViewActivity.this, "Home clicked", Toast.LENGTH_SHORT).show();
                    break;
                case R.id.action_star :
                    Toast.makeText(BottomNavigationViewActivity.this, "Star clicked", Toast.LENGTH_SHORT).show();
                    break;
                case R.id.action_money :
                    Toast.makeText(BottomNavigationViewActivity.this, "Money clicked", Toast.LENGTH_SHORT).show();
                    break;
            }

            return true;
        }
    });

    btTutorial = (Button) findViewById(R.id.bt_tutorial);
    btTutorial.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            readTheTutorial(Const.TUTORIAL_BOTTOMNAVVIEW);
        }
    });

    setupToolbar();
    super.onCreate(savedInstanceState);
}
 
Example #21
Source File: NavMainActivity.java    From AndroidDigIn with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nav_main);
    mNavigation = (BottomNavigationView) findViewById(R.id.navigation);
    mNavigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    mVp = (ViewPager) findViewById(R.id.vp);
    mVp.setAdapter(new PagerAdapter(getSupportFragmentManager()));
    mVp.addOnPageChangeListener(new PageSelectedListener());
}
 
Example #22
Source File: MainActivity.java    From atlas 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 #23
Source File: MainActivity.java    From FABRevealMenu-master 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);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

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

    showXmlFragment();

}
 
Example #24
Source File: MainActivity.java    From Nimbus with GNU General Public License v3.0 5 votes vote down vote up
public void init() {
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.nvView);

    navHeader = navigationView.getHeaderView(0);
    txtName = (TextView) navHeader.findViewById(R.id.name);
    txtSubName = (TextView) navHeader.findViewById(R.id.subname);
    imgNavHeaderBg = (ImageView) navHeader.findViewById(R.id.img_header_bg);
    imgProfile = (ImageView) navHeader.findViewById(R.id.img_profile);

    viewPager = (ViewPager) findViewById(R.id.main_view_pager);

    quiz_layout = (LinearLayout) findViewById(R.id.quiz_layout);
    gallery_layout = (LinearLayout) findViewById(R.id.gallery_layout);
    map_layout = (LinearLayout) findViewById(R.id.map_layout);
    newsfeed_layout = (LinearLayout) findViewById(R.id.newsfeed_layout);
    coreteam_layout = (LinearLayout) findViewById(R.id.coreteam_layout);
    aboutnimbus_layout = (LinearLayout) findViewById(R.id.aboutnimbus_layout);
    teams_layout = (LinearLayout) findViewById(R.id.teams_layout);
    feedback_layout = (LinearLayout) findViewById(R.id.feedback_layout);
    contributor_layout = (LinearLayout) findViewById(R.id.contributor_layout);
    sponsor_layout = (LinearLayout) findViewById(R.id.sponsor_layout);
    workshop_layout = (LinearLayout) findViewById(R.id.workshop_layout);
    bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);

}
 
Example #25
Source File: InFragmentActivity.java    From StatusBarUtil with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.use_in_fragment);

    StatusBarUtil.setTransparentForWindow(this);

    mFragmentList = Arrays.asList(
            FirstFragment.newInstance(),
            SecondFragment.newInstance(),
            ThirdFragment.newInstance(),
            FourthFragment.newInstance()
    );

    BottomNavigationView bottomMain = findViewById(R.id.bottom_main);
    bottomMain.setOnNavigationItemSelectedListener(menuItem -> {
        switch (menuItem.getItemId()) {
            case R.id.one:
                switchFragmentIndex(0);
                break;
            case R.id.two:
                switchFragmentIndex(1);
                break;
            case R.id.three:
                switchFragmentIndex(2);
                break;
            case R.id.four:
                switchFragmentIndex(3);
                break;
            default:
                break;
        }
        return true;
    });
    switchFragmentIndex(0);
}
 
Example #26
Source File: SetupWithViewPagerActivity.java    From BottomNavigationViewEx with MIT License 5 votes vote down vote up
/**
 * set listeners
 */
private void initEvent() {
    // set listener to do something then item selected
    bind.bnve.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            Log.d(TAG, item.getItemId() + " item was selected-------------------");
            // you can return false to cancel select
            return true;
        }
    });

}
 
Example #27
Source File: BottomNavigationViewInner.java    From BottomNavigationViewEx with MIT License 5 votes vote down vote up
public BottomNavigationViewInner(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TintTypedArray a = ThemeEnforcement.obtainTintedStyledAttributes(context, attrs,
            android.support.design.R.styleable.BottomNavigationView,
            defStyleAttr, android.support.design.R.style.Widget_Design_BottomNavigationView,
            new int[]{android.support.design.R.styleable.BottomNavigationView_itemTextAppearanceInactive,
                    android.support.design.R.styleable.BottomNavigationView_itemTextAppearanceActive});
    // clear if you don't have set item icon tint list
    if (!a.hasValue(android.support.design.R.styleable.BottomNavigationView_itemIconTint)) {
        clearIconTintColor();
    }
    a.recycle();
}
 
Example #28
Source File: MainActivity.java    From openlocate-android with MIT License 5 votes vote down vote up
private void initializeBottomNavigationView() {
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    getSupportFragmentManager().beginTransaction().replace(
            R.id.fragment_container,
            TrackFragment.getInstance()
    ).commit();
}
 
Example #29
Source File: BottomNavigationBehaviour.java    From triviums with MIT License 5 votes vote down vote up
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child,
                              View target, int dx, int dy, int[] consumed) {
    if (dy < 0) {
        showBottomNavigationView(child);
    } else if (dy > 0) {
        hideBottomNavigationView(child);
    }
}
 
Example #30
Source File: BrowsingActivityNavigationControllerSinglePane.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
public BrowsingActivityNavigationControllerSinglePane(int oldPanNumbers, @NonNull FragmentManager fragmentManager, boolean fromRotation, BrowsingActivity browsingActivity, @NonNull BottomNavigationView bottomNavigationView, @NonNull BrowsingActivityControllerListener listener) {
    super(oldPanNumbers, fragmentManager, fromRotation, browsingActivity, bottomNavigationView, listener);
    paneNumber = 1;
    backStackChangedListener = () -> {
        if (fragmentManager.getBackStackEntryCount() == 0) {
            bottomNavigationView.setVisibility(View.VISIBLE);
            listener.setUpNavigation(false);
        } else {
            bottomNavigationView.setVisibility(View.GONE);
            listener.setUpNavigation(true);
        }
    };
    fragmentManager.addOnBackStackChangedListener(backStackChangedListener);
}