how to add top border? - android

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>

Related

How to set text color of ChipNavigationBar

<?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>

How to change color of icons in bottom app bar

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>

android:button not working while changing checkbox default layout

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>

actionLayout not show in navigation drawer

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

My ListView background selector won't highlight the selected row

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.

Categories

Resources