我的活动中未显示BottomNavigationView [英] BottomNavigationView not showing in my activity
本文介绍了我的活动中未显示BottomNavigationView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此链接来实现BottomNavigationView 我逐步实现了所有操作,但导航视图未显示在屏幕底部.
I am implementing BottomNavigationView using this link i implemented everything step by step but my navigationview not showup at bottom of the screen.
这就是我所做的.
public class MainActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback {
Intent intent = null;
BottomNavigationView navigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
navigationView = (BottomNavigationView) findViewById(R.id.navigation);
navigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
if(id == R.id.program){
intent = new Intent(MainActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
if(id == R.id.access){
try {
manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(myIntent);
overridePendingTransition(R.anim.push_up_in,
R.anim.push_up_out);
} else {
intent = new Intent(MainActivity.this, Access.class);
startActivity(intent);
finish();
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
if(id == R.id.informations){
intent = new Intent(MainActivity.this, Information.class);
startActivity(intent);
finish();
return true;
}
if(id == R.id.contact){
intent = new Intent(MainActivity.this, Contact.class);
startActivity(intent);
finish();
return true;
}
return false;
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu = navigationView.getMenu(); <---- // -->
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
和我的activity.xml
and my activity.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite">
<android.support.design.widget.BottomNavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:design="http://schema.android.com/apk/res/android.support.design"
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
design:menu="@menu/menu_main" />
</android.support.design.widget.CoordinatorLayout>
并且我还将gradle版本更新为25,否则它将无法正常工作.
and i also updated gradle version to 25, otherwise it will not work.
compileSdkVersion 25
buildToolsVersion "24.0.3"
targetSdkVersion 25
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
推荐答案
之所以不起作用,是因为menu
在错误的命名空间(design
)中.请使用app
命名空间.
The reason it doesn't work is because menu
is in the wrong namespace (design
). Use the app
namespace instead.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite">
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
app:menu="@menu/menu_main" />
</android.support.design.widget.CoordinatorLayout>
这篇关于我的活动中未显示BottomNavigationView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文