使用androidx的BottomNavigationView
我已经创建了一些应用程序,我想在其中插入一个BottomNavigationView 代码工作得很好,但一旦我在gradle将其更改为androidx,它就停止工作了 我的布局中的组件(活动\关于): 自从我改成androidx后,有什么原因导致它不起作用吗使用androidx的BottomNavigationView,android,androidx,bottomnavigationview,material-components,material-components-android,Android,Androidx,Bottomnavigationview,Material Components,Material Components Android,我已经创建了一些应用程序,我想在其中插入一个BottomNavigationView 代码工作得很好,但一旦我在gradle将其更改为androidx,它就停止工作了 我的布局中的组件(活动\关于): 自从我改成androidx后,有什么原因导致它不起作用吗 感谢您使用androidx,您必须在中切换到 在build.gradle中添加 dependencies { //.. implementation 'com.google.android.material:material:1
感谢您使用androidx,您必须在中切换到 在
build.gradle中添加
dependencies {
//..
implementation 'com.google.android.material:material:1.2.1'
}
在布局中使用和添加:
<com.google.android.material.bottomnavigation.BottomNavigationView
.../>
我通过更换
<android.support.design.widget.BottomNavigationView
>
请参阅android文档
public class AboutActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_library:
startActivity(new Intent(AboutActivity.this, DiscoverActivity.class));
break;
case R.id.navigation_search:
Toast.makeText(AboutActivity.this, "Favorites", Toast.LENGTH_SHORT).show();
break;
case R.id.navigation_profile:
Toast.makeText(AboutActivity.this, "Nearby", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
});
}
}
dependencies {
//..
implementation 'com.google.android.material:material:1.2.1'
}
<com.google.android.material.bottomnavigation.BottomNavigationView
.../>
<android.support.design.widget.BottomNavigationView
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="56dp"
>
implementation 'com.google.android.material:material:1.2.0'