一个简单的底部导航栏,可以快速集成,简单易用
Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.wintonBy:BottomNavigationView:2.5'
}
<com.winton.bottomnavigationview.NavigationView
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/nv"
android:background="@android:color/white"
app:activeTextColor="@android:color/black"
app:unactiveTextColor="#666666"
android:layout_width="match_parent"
android:layout_height="60dp">
</com.winton.bottomnavigationview.NavigationView>
NavigationView mNV = findViewById(R.id.nv);
List<NavigationView.Model> tabs = new ArrayList<>();
tabs.add(new NavigationView.Model.Builder(R.mipmap.ic_launcher,R.mipmap.ic_launcher).title("主页").build());
tabs.add(new NavigationView.Model.Builder(R.mipmap.ic_launcher,R.mipmap.ic_launcher).title("tab1").build());
tabs.add(new NavigationView.Model.Builder(R.mipmap.ic_launcher,R.mipmap.ic_launcher).title("tab2").build());
mNV.setItems(tabs);
/*在此处监听,可获取到第一次选中到结果*/
mNV.build();
//mNV.check(0); //2.2 版本之后默认选中0
mNV.setOnTabSelectedListener(new NavigationView.OnTabSelectedListener() {
@Override
public void selected(int i, NavigationView.Model model) {
Toast.makeText(MainActivity.this,model.getTitle(),Toast.LENGTH_LONG).show();
}
@Override
public void unselected(int i, NavigationView.Model model) {
}
});
/**
* 第一个参数代表Item的位置
* 第二个参数代表是否显示红点
* 第三个参数代表红点第内容
**/
mNV.reminder(0,true,"99");
mNV.reminder(1,true,"···");
mNV.reminder(2,true,"");
Copyright 2018 Winton
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.