Contextual Action Bar Back Arrow Color Change - java

I made a Contextual Action Bar which inflates directly while long clicking on some item of the RecyclerView.
I did not create a toolbar or an appbarlayout in the xml file so the app starts without any toolbars or actionbars but when I long click on some item it inflates the contextual action bar.
My problem is, I tried all the possible methods to change the black color of the back arrow in the contextual action bar, but all in vain.

I'm not sure that you mean home up button, because it isn't part of contextual menu, it's part of activity menu.
If yes, just put this into your style
<item name="homeAsUpIndicator">#drawable/your_drawable</item>
your_drawable may look like this
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
...
</shape>
</item>
<item>
<bitmap
android:src="#android:drawable/your_image"
android:tint="#color/your_color"
/>
</item>
If no, without an image of this arrow I can't tell more.

Related

Bottom navigation view dot on the top of icon

I want my bottom nav bar like this image. I tried using a "." in label field but it did not work any suggestion how can we achieve this
The dot only appears on the selected item; so I suggest to add the dot on the icon, in that way you will have to icons for each item (selected and not selected). Then, you should use a drawable for the background of the item. Each item should be like:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/icon_with_dot"android:state_selected="true" />
<item android:drawable="#drawable/icon_without_dot" android:state_pressed="true" />

How to Change Color of Button when FireTV remote navigates over it

I am making my first Android App. This is for a firestick.
All done except for the color of the buttons.
The default light gray color is good enough (though I may change this when I find out how to).
When navigating over buttons with the remote control, the color of the button only changes to a slightly darker color. It makes it near impossible to tell which button is being navigated over.
I have gone all through the code and can find nowhere to change this to a darker color.
Changing just the background color stops the color changing at all when it is navigated over.
Where would I change this color?
As luck would have it I managed to find the answer just after I posted.
Create xml file in drawable (I used button_events.xml):
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:drawable="#color/primary_dark"/>
<item
android:state_pressed="true"
android:drawable="#color/primary_dark"/>
<item android:drawable="#color/primary" />
</selector>
Then I set my buttons background to use this drawable:
<Button
android:background="#drawable/button_events"/>

How to create a custom shape of a button but keep it clickable and focusable

I want to make a button to have a custom shape, but when I tried the shape changed, but it wasn't clickable/focusable, how do I do it?
I hope this is what you are looking for, but I have done this a couple times where I liked a rounded button a little bit more, or if it's a widget, I wanted a checkbox. Here's a couple examples I just did by just changing android:background:
<Button
android:id="#+id/widget_yes_no_checkbox_off"
android:layout_width="#dimen/checkbox_size"
android:layout_height="#dimen/checkbox_size"
android:layout_marginEnd="#dimen/right_margin"
android:layout_gravity="center"
android:background="#android:drawable/checkbox_off_background"
/>
This gave me a button that looks like a checkbox (necessary for making a checkbox in a widget).
Or, here's a drawable xml to help me round a button
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#color/primaryDarkColor"/>
<corners android:radius="20dp"/>
</shape>
with it's corresponding style theme:
<style name="myAppStyle.ButtonStyle">
<item name="android:background">#drawable/rounded_button</item>
</style>
So, in summary, I think the easiest way to do this is to still do a button layout, but use the background attribute to change the way your button looks.
You can do it by two ways,
Set any layout/button with shape drawable and add android:foreground="?attr/selectableItemBackground" in XML
Set the Style attribute in button.
style="#style/buttonTheme" in its XML and define
<style name="buttonTheme" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">#color/#000000</item> in /style folder.

Highlighting ListView Selection

I've got a (hopefully) simple question. My program has a ListView to display some data. When an item is pressed, I call the setChecked method on it to mark it as checked. How do I have this "checked" item appear highlighted or in a different style? I was doing some reading on this and found a lot of things that had to do with check-boxes, but I just want to highlight an item that is "selected" by tapping it.
EDIT: I do have a selector setup as follows:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/category_tab_s" android:state_checked="true"/>
<item android:drawable="#drawable/category_tab"/>
</selector>
However, it never applies the checked state. When I press items the category_tab state is activated.
Please check below link :
http://android-codes-examples.blogspot.in/2011/03/customized-listview-items-selection.html
Or on the onclick event you just set
view.setBackground("Any Color");
If your going t some other activity after clicking on any of the row and coming back again to the listview activity again refresh listview so that color get removed and you will get fresh listview.

how to make imagebutton in android stay highlighted?

if you click on a button in android, then it become orange, how would you make it stay like that in java? I tried setBackgroundcolor, but it change the shape of my button to the default shape when i use it and i dont want that.
It not Possible for button as it does not have permanent focus but you can take one radio button and use android:button="#drawable/yourselector". In Radio button you will get checked event and Radio Button checked is permanent state
Make a layout in res/draw able
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false"
android:state_pressed="true"
android:drawable="#drawable/btn_attending_h" /> <!--clicked-->
<item android:drawable="#drawable/btn_attending"/> <!--not clicked-->
</selector>

Categories