My BottonNavigationView not show other options, beyond the selected item. I did trying set a text color, but the color that has been changed is of the selected item.
<android.support.design.widget.BottomNavigationView
app:menu="#menu/menu_bottom"
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/darker_gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
You should be able to set colors with these parameters:
app:itemBackground
app:itemIconTint
app:itemTextColor
Here is the full code that I'm using:
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="#dimen/bottom_navigation_height"
app:itemBackground="#color/white"
app:itemIconTint="#color/bottom_bar_item_selector"
app:itemTextColor="#color/bottom_bar_item_selector"
app:menu="#menu/bottom_navigation_main" />
#color/bottom_bar_item_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#color/colorPrimary" />
<item android:color="#color/grey" />
</selector>
#menu/bottom_navigation_main.xml:
<?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/bottom_bar_item_item1"
android:icon="#drawable/ic_1"
android:title="#string/unions"
app:showAsAction="ifRoom"
android:enabled="true" />
<item
android:id="#+id/bottom_bar_item_item2"
android:icon="#drawable/ic_2"
android:title="#string/news"
app:showAsAction="ifRoom"
android:enabled="true" />
<item
android:id="#+id/bottom_bar_item_item3"
android:icon="#drawable/ic_3"
android:title="#string/dictionary"
app:showAsAction="ifRoom"
android:enabled="true" />
<item
android:id="#+id/bottom_bar_item_item4"
android:icon="#drawable/ic_4"
android:title="#string/laws"
app:showAsAction="ifRoom"
android:enabled="true" />
<item
android:id="#+id/bottom_bar_item_item5"
android:icon="#drawable/ic_5"
android:title="#string/for_members"
app:showAsAction="ifRoom"
android:enabled="true" />
</menu>
Related
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.
curently done: menu working fine with selector color change.
i want: to add a border on selected menu item. please check image for result i want.
attched: 1. activitymain 2. selector 3. menu_nevigation
can i get border on selected item.
activityMain.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=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"
android:textSize="50sp"
android:textStyle="bold"
android:layout_centerInParent="true" />
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_above="#id/bottom_navigation"
android:background="#drawable/shadow"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bottom_navigation"
app:itemBackground="#color/colorcustom"
app:itemTextColor="#drawable/selector"
app:itemIconTint="#drawable/selector"
app:menu="#menu/menu_navigation"
app:labelVisibilityMode="labeled"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:color="#333333"
/>
<item
android:state_selected="false"
android:color="#a6a6a6"/>
</selector>
menu_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/home"
android:title="Home"
android:icon="#drawable/ic_home"/>
<item
android:id="#+id/about"
android:title="About"
android:icon="#drawable/ic_about"/>
<item
android:id="#+id/test"
android:title="Test"
android:icon="#drawable/ic_test"/>
<item
android:id="#+id/term"
android:title="Term"
android:icon="#drawable/ic_term"/>
<item
android:id="#+id/setting"
android:title="Setting"
android:icon="#drawable/ic_setting"/>
</menu>
Android Studio 3.6
in my xml layout:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/feedbackContainer"
android:layout_width="0dp"
android:layout_height="174dp"
app:layout_constraintEnd_toEndOf="#+id/checkContainer"
app:layout_constraintStart_toStartOf="#+id/checkContainer"
app:layout_constraintTop_toBottomOf="#+id/checkContainer">
<ImageView
android:id="#+id/feedbackViewCircle"
android:layout_width="124dp"
android:layout_height="124dp"
android:background="#drawable/circle_bg"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#+id/heartOutlineNotMadeContainer"
android:layout_width="56dp"
android:layout_height="56dp"
android:background="#drawable/feedback_outline_bg"
app:layout_constraintBottom_toBottomOf="#+id/feedbackViewCircle"
app:layout_constraintEnd_toEndOf="#+id/feedbackViewCircle"
app:layout_constraintStart_toStartOf="#+id/feedbackViewCircle"
app:layout_constraintTop_toTopOf="#+id/feedbackViewCircle" />
<TextView
android:id="#+id/feedbackTextView"
style="#style/defaultTextStyle2"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:text="#string/feedback"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/feedbackViewCircle" />
</androidx.constraintlayout.widget.ConstraintLayout>
/circle_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/circle_paint_dark" android:state_enabled="false" />
<item android:drawable="#drawable/circle_paint" />
</selector>
/feedback_outline_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_heartoutlinemade" android:state_enabled="false" />
<item android:drawable="#drawable/ic_heartoutlinenotmade" />
</selector>
here background/feedbackViewCircle.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/circle_paint_dark" android:state_enabled="false" />
<item android:drawable="#drawable/circle_paint" />
</selector>
And here result:
OK. It's work.
But I need to have "press" effect. Smt like this:
Make the View clickable and add selector for normal and pressed state background, which work perfectly.
<View
android:id="#+id/feedbackViewCircle"
android:layout_width="124dp"
android:layout_height="124dp"
android:clickable="true"
android:background="#drawable/circle_bg"
...
/>
circle_bg.xml for background selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/circle_paint_dark" android:state_pressed="true" />
<item android:drawable="#drawable/circle_paint" />
</selector>
Assuming I understand the question, my advice is that you use a style that extends Widget.Design.FloatingActionButton and then apply it to your view like so
<style name="FeedbackAppearance" parent="Widget.Design.FloatingActionButton">
<item name="android:layout_width">#dimen/some_width</item>
<item name="android:layout_height">#dimen/some_height</item>
<item name="android:layout_margin">#dimen/std_gap</item>
<item name="layout_anchorGravity">end|bottom</item>
...
</style>
// inside layout file
<View
style="#style/FeedbackAppearance"
...
/>
You can modify any of the following style attributes or add different ones.
<style name="Widget.Design.FloatingActionButton" parent="android:Widget">
<item name="android:background">#drawable/design_fab_background</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
<item name="backgroundTint">?attr/colorAccent</item>
<item name="fabSize">auto</item>
<item name="elevation">#dimen/design_fab_elevation</item>
<item name="hoveredFocusedTranslationZ">#dimen/design_fab_translation_z_hovered_focused</item>
<item name="pressedTranslationZ">#dimen/design_fab_translation_z_pressed</item>
<item name="rippleColor">?attr/colorControlHighlight</item>
<item name="borderWidth">#dimen/design_fab_border_width</item>
<item name="maxImageSize">#dimen/design_fab_image_size</item>
<item name="showMotionSpec">#animator/design_fab_show_motion_spec</item>
<item name="hideMotionSpec">#animator/design_fab_hide_motion_spec</item>
</style>
So I want a navigation bar at the bottom of the screen with 4 items but for some reason only the first one is showing and the others appear only when i click them.
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/white"
app:itemTextColor="#color/black"
app:menu="#menu/navigation_bar_bottom_menu" />
My menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/nav_home"
android:title="#string/navigation_bar_home_text" />
<item
android:id="#+id/nav_inbox"
android:title="#string/navigation_bar_inbox_text" />
<item
android:id="#+id/nav_notes"
android:title="#string/navigation_bar_notes_text" />
<item
android:id="#+id/nav_profile"
android:title="#string/navigation_bar_profile_text" />
</menu>
The bar is displayed like this just with the first item showing:
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/gray_background"
app:itemIconTint="#color/nav_item_state_list"
app:itemTextColor="#color/nav_item_state_list"
app:labelVisibilityMode="labeled"
android:theme="#style/Widget.BottomNavigationView"
app:menu="#menu/bottom_navigation_items"/>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/colorPrimaryLite"
android:state_pressed="true"/>
<item android:color="#color/colorPrimaryLite"
android:state_checked="true"/>
<item android:color="#color/grayDark"
android:state_checked="false"/>
<item android:color="#color/white"/>
</selector>
Here is the example
Create a color file
navigation_item_text_color.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#color/black" />
<item android:color="#android:color/darker_gray" />
</selector>
then put to color folder (if you don't have color folder -> just create it manually)
Then
<com.google.android.material.bottomnavigation.BottomNavigationView
...
app:itemTextColor="#color/navigation_item_text_color" />
More
If you bottom menu item have icon, you can change icon color like
app:itemIconTint="#color/navigation_item_text_color"
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: