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'
Your Activity works? I miss the code for onCreate()!
Please add an id for the BottomNavigationView eg:
<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 (eg ic_home_black_24dp, see picture) in the drawable folder and shown in Android Studio when displaying menu.xml?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.