I'm trying to create something that's similar to this bottom navigation bar. I would really appreciate any help you can give me :
This is my menu xml code (bottom_navigation_main):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_1"
android:enabled="true"
android:icon="#drawable/ic_1"
android:title="Home"
app:showAsAction="ifRoom" />
<item
android:id="#+id/action_2"
android:enabled="true"
android:icon="#drawable/ic_2"
android:title="Free"
android:textColor="#drawable/nav_bar_selector"
app:showAsAction="ifRoom" />
<item
android:id="#+id/action_3"
android:enabled="true"
android:icon="#drawable/ic_food_white"
android:title="Other"
android:textColor="#drawable/ic_3"
app:showAsAction="ifRoom" />
<item
android:id="#+id/action_4"
android:enabled="true"
android:icon="#drawable/ic_4"
android:title="Other"
android:textColor="#drawable/nav_bar_selector"
app:showAsAction="ifRoom" />
<item
android:id="#+id/action_5"
android:enabled="true"
android:icon="#drawable/ic_5"
android:title="Other"
android:textColor="#drawable/nav_bar_selector"
app:showAsAction="ifRoom" />
</menu>
This is my main layout code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/fullyTransparent"
android:fitsSystemWindows="true"
android:id="#+id/rlLeftDrawer"
android:layout_weight="1"
>
<RelativeLayout
android:id="#+id/rlContentHolder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/fullyBlack"
app:itemIconTint="#color/fullyWhite"
app:itemTextColor="#color/fullyWhite"
app:menu="#menu/bottom_navigation_main" />
</RelativeLayout>
</RelativeLayout>
I'm not sure where to go from here. I successfully implemented the new bottom nav bar from Android but I'm having issues styling it.
It currently looks like this:
Related
Can I know why the texts inside the navigation drawer are not the same?
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
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=".activities.MainActivity"
tools:openDrawer="start">
...
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/menu_navigation_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
----------
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Other">
<menu>
<item
android:icon="#drawable/ic_star"
android:title="Rate the app" />
<item
android:icon="#drawable/ic_share"
android:title="Share the app" />
<item
android:icon="#drawable/ic_shield"
android:title="Privacy policy" />
<item
android:icon="#drawable/ic_document"
android:title="Terms of services" />
</menu>
</item>
</menu>
Notice some items have bold texts and some items have regular texts.
Why is that happening?
I'm using Material Design 3.
The solution
<style name="styleName" parent="TextAppearance.Material3.LabelLarge">
<item name="fontFamily">#font/font_regular</item>
</style>
Then add this inside NavigationView
app:itemTextAppearance="#style/styleName"
I am trying to implement bottom navigation in fragment but some how it is not working. There is no preview for bottom navigation bar in design tab.
Here is my code for fragment xml
<?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=".studentPanel.hostFragment.StudentPanelFragment">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav_st_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_nav_menu" />
</RelativeLayout>
Here is the code for menu xml file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/profile"
android:enabled="true"
android:icon="#drawable/profile"
android:title="#string/profile" />
<item
android:id="#+id/conveyance"
android:enabled="true"
android:icon="#drawable/conveyance"
android:title="#string/conveyance" />
<item
android:id="#+id/home"
android:enabled="true"
android:icon="#drawable/home"
android:title="#string/home" />
<item
android:id="#+id/fee"
android:enabled="true"
android:icon="#drawable/fee"
android:title="#string/fee_receipt" />
<item
android:id="#+id/event"
android:enabled="true"
android:icon="#drawable/event"
android:title="#string/event" />
</menu>
I am not able to figure where is error in this code.
<?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=".MainActivity"
android:id="#+id/fragment_container">
<com.ismaeldivita.chipnavigation.ChipNavigationBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:id="#+id/bottom_nav_menu"
app:cnb_textColor ="#color/white"
app:cnb_unselectedColor="#color/black"`enter code here`
android:layout_marginBottom="5dp"
app:cnb_menuResource="#menu/bottom_navigation_menu_chef"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
How I can set the text color of the selected item using this library on any other way?
In menu item add app:cnb_textColor="#color/home_label"
As i see.. You can set the selected color changing the cnb_textColor in the bottom_navigation_menu_chef.
I will get you an example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/home"
android:icon="#drawable/ic_home"
android:title="Home"
app:cnb_textColor="#android:color/holo_red_dark"/>
<item
android:id="#+id/activity"
android:icon="#drawable/ic_activity"
android:title="Activity"
app:cnb_textColor="#android:color/holo_green_dark"/>
<item
android:id="#+id/favorites"
android:icon="#drawable/ic_heart"
android:title="Favorites"
app:cnb_textColor="#android:color/black"/>
<item
android:id="#+id/settings"
android:icon="#drawable/ic_settings"
android:title="Settings"
app:cnb_textColor="#android:color/holo_blue_light" />
</menu>
I wanted to change the color of icons in the bottom app bar. I am using the bottom app bar for the first time so I don't have any prior knowledge of it.
The code of the XML file having bottom app bar is below
<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=".NavigActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottom_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="#color/colorAccent"
app:navigationIcon="#drawable/ic_menu_black_24dp"
app:menu="#menu/menu"
app:buttonGravity="center_vertical"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_black_24dp"
app:layout_anchor="#id/bottom_app_bar"
android:backgroundTint="#color/colorPrimary"
app:maxImageSize="35dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/content_frame"
/>
</RelativeLayout>
The menu file used in this is below
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/home"
android:title="Home"
android:icon="#drawable/ic_home_black_24dp"
app:showAsAction="ifRoom"
/>
<item
android:id="#+id/my_invoices"
android:title="Invoices"
android:icon="#drawable/ic_receipt_black_24dp"
app:showAsAction="ifRoom"
/>
<item
android:id="#+id/notification"
android:title="Notification"
android:icon="#drawable/ic_notifications_black_24dp"
app:showAsAction="ifRoom"
/>
</menu>
I wanted the color o the icon to change to primaryColor but it is not changing..Any help would be appreciated
You can try on menu.xml
Find the detail on link. (image)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="[URL]http://schemas.android.com/apk/res/android[/URL]"
xmlns:app="[URL]http://schemas.android.com/apk/res-auto[/URL]">
<item
android:id="#+id/menu_color_change"
android:title="Color Plate"
app:showAsAction="ifRoom"
android:icon="#drawable/ic_color_plate">
</item>
<item
android:id="#+id/menu_other"
android:title="Other"
app:showAsAction="never"
android:iconTint="#android:color/white"
android:icon="#drawable/ic_color_plate">
</item>
</menu>
I use the MvvmCross Resx Localization plugin. This works fine for all the layouts I have. But all the menues are untranslated. I have this xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto">
<group android:id="#+id/nav_items">
<item
android:id="#+id/nav_accounts"
android:icon="#drawable/ic_account_balance"
local:MvxLang="Text AccountsLabel" />
<item
android:id="#+id/nav_statistics"
android:icon="#drawable/ic_show_chart"
local:MvxLang="Text StatisticsLabel" />
</group>
<group android:id="#+id/nav_footer">
<item
android:id="#+id/nav_categories"
android:icon="#drawable/ic_label_outline"
local:MvxLang="Text CategoriesLabel" />
<item
android:id="#+id/nav_backup"
android:icon="#drawable/ic_backup"
local:MvxLang="Text BackupLabel" />
<item
android:id="#+id/nav_settings"
android:icon="#drawable/ic_settings"
local:MvxLang="Text BackupLabel" />
<item
android:id="#+id/nav_about"
android:icon="#drawable/ic_info"
local:MvxLang="Text AboutLabel" />
</group>
</menu>
And I include it here:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.NavigationView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.Menu"
local:headerLayout="#layout/fragment_navigation_header"
local:menu="#menu/navigation_drawer" />
Also I have the viewmodel with the TextSource definition:
public IMvxLanguageBinder TextSource => new MvxLanguageBinder("", GetType().Name);
I made a constructor and resolved the label I want. For example "AboutLabel". This worked without any issues.
Is there a fix that the menu works as well ?