<?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>
Related
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>
I want to customize my checkbox for which i am trying to set the button and assinging it my selector. But the checkbox disappears completely and nothing is shown. Here is the code:
<CheckBox
android:id="#+id/bollywood_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/relationship"
android:layout_alignParentEnd="true"
android:layout_marginTop="5dp"
android:button="#drawable/check_background" />
My selector file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/bg_comment" android:state_checked="true"/>
<item android:drawable="#drawable/bg_et"/>
</selector>
Try this out, It is working for me
selector_checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_checkbox_on" android:state_checked="true"/>
<item android:drawable="#drawable/ic_checkbox_off" android:state_checked="false"/>
</selector>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<CheckBox
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="#+id/bollywood_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:button="#drawable/selector_checkbox"
android:text="Hello"
android:layout_marginTop="5dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
I'm having some trouble using custom layout as a menu item in a navigation drawer. When I use app:actionLayout just a title is shown.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/colorPrimary"
android:fitsSystemWindows="true"
app:headerLayout="#layout/drawer_menu_header"
app:itemIconTint="#color/colorGray"
app:itemTextColor="#color/colorGray"
app:menu="#menu/drawer_menu">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
drawer_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="navigation_view">
<group android:id="#+id/menu_grp1" android:checkableBehavior="single">
<item
android:id="#+id/menu_add_event"
android:icon="#drawable/menu_add"
android:title="#string/menu_add_event"/>
<item
android:id="#+id/menu_add_service"
android:icon="#drawable/menu_add"
android:title="#string/menu_add_service"/>
</group>
<group android:id="#+id/menu_grp2" android:checkableBehavior="single">
<item
android:id="#+id/menu_home"
android:icon="#drawable/menu_home"
android:title="#string/menu_home"/>
<item
android:id="#+id/menu_event"
android:icon="#drawable/menu_event"
android:title="#string/menu_event"/>
<item
android:id="#+id/menu_interesting"
android:icon="#drawable/menu_interesting"
android:title="#string/menu_interesting"/>
<item
android:id="#+id/menu_service"
android:icon="#drawable/menu_service"
android:title="#string/menu_service"/>
<item
android:id="#+id/menu_about"
android:icon="#drawable/menu_about"
android:title="#string/menu_about" />
<item
android:id="#+id/menu_advertising"
android:icon="#drawable/menu_advertising"
android:title="#string/menu_advertising" />
</group>
<group android:id="#+id/menu_grp3" android:checkableBehavior="single">
<item
android:id="#+id/menu_news"
android:icon="#drawable/menu_news"
android:title="#string/menu_news"/>
<item
android:id="#+id/menu_favorite"
android:icon="#drawable/menu_favorite"
android:title="#string/menu_favorite" />
<item
android:id="#+id/menu_visited"
android:icon="#drawable/menu_visited"
android:title="#string/menu_visited" />
<item
android:id="#+id/menu_logout"
android:icon="#drawable/menu_logout"
android:title="#string/menu_logout" />
</group>
<group android:id="#+id/menu_grp4" android:checkableBehavior="single">
<item
android:id="#+id/menu_social"
android:title="title"
app:actionLayout="#layout/drawer_menu_footer"
app:showAsAction="always"
android:visible="true"/>
</group>
</menu>
drawer_menu_footer.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/menu_facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/menu_social_buttons_margin"
app:srcCompat="#drawable/menu_facebook" />
<ImageView
android:id="#+id/menu_instagram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/menu_social_buttons_margin"
app:srcCompat="#drawable/menu_instagram" />
<ImageView
android:id="#+id/menu_p"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/menu_pinterest" />
</LinearLayout>
I solved my problem by replacing app:srcCompat with android:background in drawer_menu_footer.xml
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:
I used this SO question as a guide, but when I click a row it doesn't stay highlighted. What is wrong with my code?
score_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/score_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/keyboard"
android:listSelector="#drawable/selector"
android:choiceMode="singleChoice"
android:divider="#CCCCCC"
android:dividerHeight="1dp"
android:paddingLeft="15dp"
android:paddingRight="15dp" />
...
</RelativeLayout>
drawable/selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="#color/highlight"/>
<item android:state_pressed="true" android:drawable="#color/highlight"/>
</selector>
score_row_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scoreRowLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#drawable/row_selector" >
...
</LinearLayout>
drawable/row_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:drawable="#color/highlight" />
<item android:state_activated="true" android:drawable="#color/highlight" />
<item android:drawable="#color/transparent" />
</selector>
This code now works properly.
Try to use state_activated for your row_selector.