# BottomNavigation
**Repository Path**: HarmonyOS-tpc/BottomNavigation
## Basic Information
- **Project Name**: BottomNavigation
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 10
- **Forks**: 3
- **Created**: 2021-04-01
- **Last Updated**: 2024-09-27
## Categories & Tags
**Categories**: harmonyos-menu
**Tags**: None
## README
# Demo
# used?
```
dependencies{
implementation 'io.openharmony.tpc.thirdlib:BottomNavigation:1.0.3'
}
```
```xml
```
```java
bottomNavigationBar = (BottomNavigationBar)findComponentById(ResourceTable.Id_bar);
numberBadgeItem = new TextBadgeItem()
.setBorderWidth(DpUtils.dp2px(1.5f,getContext()))
.setBackgroundColor(0xffff5454)
.setText("2")
.setHideOnSelect(true);
shapeBadgeItem = new ShapeBadgeItem()
.setShape(shapeBadge)
.setShapeColor(0xffff5454)
.setOffset(DpUtils.dp2px(20,getContext()),DpUtils.dp2px(-20,getContext()))
.setHideOnSelect(true);
bottomNavigationBar.clearAll();
bottomNavigationBar.setBarMode(mode);
bottomNavigationBar.setBackgroundStyle(backgroundSytle);
if(countItem == 0){
bottomNavigationBar
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_location_on_white_24dp, "Nearby",getContext()).setActiveColor(0xffF57C00).setBadgeItem(numberBadgeItem))
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_find_replace_white_24dp, "Find",getContext()).setActiveColor(0xff00796B))
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_favorite_white_24dp, "Categories",getContext()).setActiveColor(0xff2196F3).setBadgeItem(shapeBadgeItem))
.setFirstSelectedPosition(0)
.initialise();
}else if(countItem == 1){
bottomNavigationBar
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_home_white_24dp, "Home",getContext()).setActiveColor(0xffF57C00).setBadgeItem(numberBadgeItem))
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_book_white_24dp, "Books",getContext()).setActiveColor(0xff00796B))
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_music_note_white_24dp, "Music",getContext()).setActiveColor(0xff2196F3).setBadgeItem(shapeBadgeItem))
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_tv_white_24dp, "Movies & TV",getContext()).setActiveColor(0xff8D6E63))
.setFirstSelectedPosition(0)
.initialise();
}else if(countItem == 2){
bottomNavigationBar
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_home_white_24dp, "Home",getContext()).setActiveColor(0xffF57C00).setBadgeItem(numberBadgeItem))
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_book_white_24dp, "Books",getContext()).setActiveColor(0xff00796B))
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_music_note_white_24dp, "Music",getContext()).setActiveColor(0xff2196F3).setBadgeItem(shapeBadgeItem))
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_tv_white_24dp, "Movies & TV",getContext()).setActiveColor(0xff8D6E63))
.addItem(new BottomNavigationItem(ResourceTable.Media_ic_videogame_asset_white_24dp, "Games",getContext()).setActiveColor(0xff607D8B))
.setFirstSelectedPosition(0)
.initialise();
}
```
# API:
## class:BottomNavigationBar
**public BottomNavigationBar addItem(BottomNavigationItem item)**
- description: add item
**public BottomNavigationBar removeItem(BottomNavigationItem item)**
- description: remove item
**public BottomNavigationBar setBarMode(int mode)**
- description: set mode
**public BottomNavigationBar setBackgroundStyle(int backgroundStyle)**
- description: set background style
**public BottomNavigationBar setActiveColor(int activeColor)**
- description:set active color
**public BottomNavigationBar setInActiveColor(int inActiveColor)**
- description:set in-active color
**public BottomNavigationBar setBackgroundColor(int backgroundColor)**
- description:set background color
**public BottomNavigationBar setFirstSelectedPosition(int position)**
- description:set first selected position
**public BottomNavigationBar setTabSelectedListener(OnTabSelectedListener tabSelectedListener)**
- description:set tab selected listener
**public void selectTab(int newPosition)**
- description:select tab
**public void selectTab(int newPosition, boolean callListener)**
- description:setect tab need call listener
**public void toggle(boolean animate)**
- description:toggle bar
**public void show()**
- description:show bar
**public void show(boolean animate)**
- description:show bar with animate
**public void hide()**
- description:hide bar
**public void hide(boolean animate)**
- description:hide bar with animate
**public boolean isHidden()**
- description:is hidden?
**public int getActiveColor()**
- description:get active color
**public int getInActiveColor()**
- description:get in-active color
**public int getCurrentSelectedPosition()**
- description:get current selected position
**public int getAnimationDuration()**
- description:get animation duration
**public BottomNavigationBar setTouchEffect(boolean touchEffect)**
- description:set touch effect
**public boolean getTouchEffect()**
- description:get touch effect
## class:BottomNavigationItem
**public BottomNavigationItem setActiveColor(int color)**
- description:set active color
**public BottomNavigationItem setInActiveColor(int color)**
- description:set in-active color
**public String getTitle()**
- description:get titile
**public BottomNavigationItem setBadgeItem(BadgeItem badgeItem)**
- description:set badge item
**public BadgeItem getBadgeItem()**
- description:get badge item
# AttrSet:
|name|format|description|
|:---:|:---:|:---:|
| bnbActiveColor | color | set active color
| bnbInactiveColor | color | set in-active color
| bnbBackgroundColor | color | set background color
| bnbElevation | dimension | set elevation dimension
| bnbAnimationDuration | int | set animation duration
| bnbMode | int | set mode
| bnbBackgroundStyle | int | set background style
| bnbTouchEffect | int | set touch effect