I wanna make a bottom navigationview like instagram. I have an image and to show it in this view I have to write this,
bottomNavigation.setItemIconTintList(null);
but after that I cant see which menu item is selected because color always same in every item. So any ideas ?
You should add the item_selector.xml such as :
<?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/colorPrimaryDark"/>
<item android:color="#android:color/darker_gray"/>
</selector>
and set it to your BottomNavigationView component that inside the xml file
app:itemTextColor="#drawable/nav_item_selector"
Related
I want to change the color of check box button as when it gets focus its background color will change and when it has no focus it will remain the same.
I have tried using selector but not able to change it
can any one help me out in this
Use this:
Backround-color: 'any color'
Create drawable file like this :
checkbox_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/pink"/>
<item android:state_checked="false" android:color="#color/checkbox_not_selected"/>
</selector>
Apply it like this :
<androidx.appcompat.widget.AppCompatCheckBox
android:id="#+id/chkSelected"
android:layout_width="#dimen/_23sdp"
android:layout_height="#dimen/_23sdp"
android:layout_alignParentEnd="true"
android:buttonTint="#drawable/checkbox_color"
android:checked="false"
android:clickable="false" />
then change it runtime like this to change color runtime based on of it is selected :
chkSelected.isSelected = true
or
chkSelected.isSelected = false
add a new color file in your project. (right click on res then new>android recourse file and put the recourse type on Color )
fill this file with this code :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#ce0e0e" />
<item android:state_checked="false" android:color="#6fc97d"/>
</selector>
then in your CheckBox add this color as your checkBox Color.
you can change your color when checked is true or false in your sample color file
I'm trying to make this NavigationBottomView:
All I want is to make selected item text instead of icon.
I googled it and tried to make custom navigationBottomView item, but I found nothing like what I want.
is it possible to be a text ? or even can i hide the icon and display item title only ?
Yes it's.
To control toggling BottomNavigationView item text, use app:itemTextColor with a custom selector
In your case you need to show up the text when an item is checked, and hide it otherwise.
To control toggling the item icon, use app:itemIconTint with a custom selector
In your case you need to show up the icon when an item is unchecked, and hide it otherwise.
For both text/icon cases you can use a transparent color as a hack for the hidden state.
Example:
<com.google.android.material.bottomnavigation.BottomNavigationView
...
app:itemTextColor="#drawable/text_selector"
app:itemIconTint="#drawable/icon_selector"
text_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#FFEB3B" android:state_checked="true" />
<item android:color="#android:color/transparent" android:state_checked="false" />
</selector>
icon_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#FFEB3B" android:state_checked="false" />
<item android:color="#android:color/transparent" android:state_checked="true" />
</selector>
UPDATE
i tried it before but all i got icon get hidden and text still at the
bottom not shifted to the center like gif u sent
You can have the same behavior by changing the BottomNavView text size:
Create the following style to increase the item text:
<style name="BottomNavigationViewActiveItemText" parent="#style/TextAppearance.AppCompat.Caption">
<item name="android:textSize">20sp</item>
</style>
Apply it to the BottomNavigationView with app:itemTextAppearanceActive="#style/BottomNavigationViewActiveItemText"
If your item text can be in two lines, use also:
<style name="BottomNavigationStyle">
<item name="android:gravity">center</item>
<item name="android:lines">2</item>
</style>
And apply it with android:theme="#style/BottomNavigationStyle"
I am using Leanback BrowseFragment and need to be able to set background colour of header item when selected. Any direct method/XML attributes available to do that? I have been looking into BrowseFragment and leanback themes.xml.
Reference:
https://developer.android.com/reference/android/support/v17/leanback/app/BrowseFragment.html
https://android.googlesource.com/platform/frameworks/support/+/master/v17/leanback/res/values/themes.xml
In my case I used custom header items with icons. You can see details in this tutorial. For TextView from my layout I defined xml file in the color directory, something like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/accent_color" android:state_selected="true"/>
<item android:color="#color/white"/>
</selector>
and the same xml files (but with android:drawable attributes ) in the direcroty drawable.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/icon_focused"
android:state_selected="true"/>
<item android:drawable="#drawable/icon"/>
</selector>
Then simply set android:textColor="#color/your_new_xml_file" for TextViewand use your drawable files for your header ImageView.
If you need to change View background, not only header icon and text color, set such xml file with defined colors as a View background.
OnSelectLevelChanged() method in my presenter class is empty (without this, like in tutorial above) :
holder.view.setAlpha(mUnselectedAlpha + holder.getSelectLevel() *
(1.0f - mUnselectedAlpha));
I need to make a style like following screen shot
PLZ NEED HELP !!!!
I have tried using make custom style
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/buttion_inner_icon" android:state_checked="true"/>
<item android:drawable="#drawable/buttion_inner_icon" android:state_checked="false"/>
</selector>
But its not as I want
Please help me to make view same as screen shot
You have setted the same drawable when state_checked = true and state_checked = false.
You must have two differents drawables.
You can use a ToggleButton for this. In your xml file, set the text to an empty string, otherwise it will show 'on' and 'off'.
android:textOff=""
android:textOn=""
Then you have to add two drawables: one with the handle on the left side (so that 'check in' is visible, this is the unchecked state, name it for example 'check_in_unchecked'), and one with handle on the right side (so that 'check out' is visible, this is the checked state, name it for example 'check_in_checked'). After that, add a selector as background of your ToggleButton:
android:background="#drawable/selector_check_in"
selector_check_in will look like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/check_in_checked" android:state_checked="true"/>
<item android:drawable="#drawable/check_in_unchecked" android:state_checked="false"/>
</selector>
Hey I'm trying to add a selected state to my Nav Drawer. Everything is pretty boilerplate from the implementation here: http://developer.android.com/training/implementing-navigation/nav-drawer.html
There's some custom style in there and I'm trying to style a custom selected state for the List View (the list view that is actually the nav drawer)
I created a selector for the list items:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#color/darkerGrey" android:state_pressed="true"/>
<item android:drawable="#color/mediumGrey" android:state_selected="true"/>
</selector>
and I'm seeing the style work for the "pressed" state, but I'm not seeing the "selected" state work. In code to make it selected I'm using the ListView method setItemChecked:
mDrawerList.setItemChecked(0, true);
I've also set on my ListView the property
android:choiceMode="singleChoice"
I would greatly appreciate any advice! Thanks!
p.s. I've tried using "state_checked" as well, to no avail.
try setting this selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#color/darkerGrey" android:state_pressed="true"/>
<item android:drawable="#color/mediumGrey" android:state_selected="true"/>
</selector>
to the listView as:
android:listSelector="#drawable/your_selector"
or
to the list_row_layout that you use for inflating into the list as:
android:background="#drawable/your_selector"