Solution 1 :
Your Activity works? I miss the code for onCreate()!
Please add an id for the BottomNavigationView e.g.:
<com.google.android.material.bottomnavigation.BottomNavigationView
android_id="@+id/navigation"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_layout_gravity="bottom"
android_background="?android:attr/windowBackground"
app_menu="@menu/navigation" />
In your Activity must be code like this. Is it there?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener( mOnNavigationItemSelectedListener);
}
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
// ... implement code here
}
return false;
}
};
Edit: are the icons (e.g. ic_home_black_24dp, see picture) in the drawable folder and shown in Android Studio when displaying menu.xml?
Solution 2 :
i found the answer here:
Rendering Issue in Android Studio
seems it was a rendering issue with the theme and had to change to appcompat.
thank you
Problem :
I’m trying to make a bottom Nav using android studio, but it will not display. if I add height to it, I can see the BG color but still no content of the menu items
EDIT:
its treating the menu xml as empty.
here is my code, ive also tried changing the layout to linear, frame and constraint:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns_android="http://schemas.android.com/apk/res/android"
xmlns_app="http://schemas.android.com/apk/res-auto"
xmlns_tools="http://schemas.android.com/tools"
android_layout_width="match_parent"
android_layout_height="match_parent"
tools_context=".HomeScreen">
<com.google.android.material.bottomnavigation.BottomNavigationView
android_layout_width="match_parent"
android_layout_height="wrap_content"
app_menu="@menu/menu"
android_layout_alignParentBottom="true"
android_background="@color/btnSignUp"/>
</RelativeLayout>
here is my menu item, its located in a menu folder
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns_android="http://schemas.android.com/apk/res/android">
<item
android_id="@+id/nav_home"
android_icon="@drawable/ic_home_black_24dp"
android_title="Home"
/>
<item
android_id="@+id/nav_search"
android_icon="@drawable/ic_search_black_24dp"
android_title="Search"
/>
<item
android_id="@+id/nav_orders"
android_icon="@drawable/ic_receipt_black_24dp"
android_title="Orders"
/>
<item
android_id="@+id/nav_account"
android_icon="@drawable/ic_person_black_24dp"
android_title="My Account"
/>
</menu>
and lastly my dependencies:
implementation 'com.github.jd-alexander:android-flat-button:1.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-firestore:21.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.android.material:material:1.1.0'
Comments
Comment posted by M123
Did you solve this problem ?
Comment posted by Emil C.
i’ve tried it but it still wont display anything. i think its treating the menu xml as empty
Comment posted by Cor
are the icons (e.g. ic_home_black_24dp) in the drawable folder and shown in Android Studio when displaying menu.xml?