Changing navigation back button icon dynamically doesn't work - android

I need to set navigation back button dynamically
when I do this `
viewBinding.toolbar.navigationIcon?.setColorFilter(Color.parseColor(theme.primaryTextColor), PorterDuff.Mode.MULTIPLY)
it doesn't effect changing color or if I do
viewBinding.toolbar.setNavigationIcon(R.drawable.ic_back) in MainActivity
where ic_back is white back button it doesn't work it shows back button
or if I add this app:navigationIcon="#drawable/ic_back" in xml it doesn't work
but when I set app:theme="#style/ToolbarColoredBackArrow"
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">#FFFFFF</item>
</style>
it works why? I should do this without using theme

If the toolbar is your support action bar, then this definitely works :
toolbar.setNavigationIcon(R.drawable.ic_back);
Or whatever you want to set the icon to, just that it has to be a drawable file.

Related

How to change the up navigation icon in android on searchview expand

i'm using actionbarsherlock for my actionbar. I have a sliding menu and searchview. when the application get launches, it will automatically pick the up navigation icon from style.xml file.
When the search menu gets expanded, the up navigation icon will not get changed, it will be still looking like 3 line slider menu. How to change the up navigation icon when searchview is expanded?. I have represented the flow in below image.
Create custom back button theme with parent of your custom theme.
<style name="MyThemeForSearch" parent="#style/MyCustomTheme">
<item name="android:homeAsUpIndicator">#drawable/my_back_indicator_for_search</item>
</style>
Set theme in runtime when Search is expanded., i.e onClick
setTheme(R.style.MyThemeForSearch);
check your layout drawable's whether you have set an image like 3 liner slide menu
when you create navigation drawer it automatically sets default image which will be loaded representing 3 liner slide like you mentioned change your ic_drawer.png image and replace image with what icon you wish.
also you might go check changing your theme
> <style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
> <item name="android:homeAsUpIndicator">#drawable/my_fancy_up_indicator</item>
> </style>

Apply color change in Action bar navigation button

I've been to the documentation, I'm still lost how to change the color on the navigation icon thing with 3 dashes near the app logo.
That "thing" is the homeasupindicator icon. You can change it in your styles.xml file, by customizing your Theme, modifying the android:homeAsUpIndicator attribute.
In your Manifest.xml you can define your Theme for your whole application, or for each of your Activities.
So, add a style to your styles.xml, like this:
<style name="Theme.MyCustomTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">#drawable/my_indicator_drawable</item>
Then, on your Manifest.xml, do:
android:theme="#style/Theme.MyCustomTheme"
This will override the icon on the ActionBar.
Don't forget to call getSupportActionBar().setDisplayHomeAsUpEnabled(true); to activate the icon behaviour.

Remove pressed effect on action bar home icon

First, a few words about the app : minimum level is 16, I use a DrawerLayout (with the indicator) and have changed the background of my ActionBar.
When clicking on the home button to open the drawer, there is a blue pressed effect on both the image and the drawer indicator, that I'd like to remove. I tried setting selectableItemBackground in the styles to transparent, nearly everywhere I could think of, but that doesn't seem to change anything. Do anyone have a solution ?
Here is the image of this effect I'd like to remove :
Here is the styles.xml part for the ActionBar I'm using :
<style name="ActionBar.Solid.Bnp" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/action_bar_green</item>
<item name="android:titleTextStyle">#style/ActionBar.Title</item>
<item name="android:actionBarItemBackground">#null</item>
</style>
and finally the drawable used for background.
selectableItemBackground is close, but you need to use the actionBarItemBackground attribute instead.
For instance:
<style name="Your.Theme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#null</item>
</style>
You should keep in mind that the system uses this attribute in the ActivityChooserView too, which is what the ShareActionProvider returns in ActionProvider.onCreateActionView.
To highlight all this, here are the results when you use #android:color/holo_red_light instead:

How to make an icon in a style clickable?

I have a universal style for my sherlock actionbar set like so:
<style name="app_action_bar" parent="#style/Widget.Sherlock.ActionBar.Solid">
<item name="android:icon">#drawable/logo</item>
</style>
How do I make the logo clickable, and set an onclickhandler?
The icon is a special application icon (android.R.id.home) details of handling on click are here:
Clicking app icon doesn't trigger onOptionsItemSelected()

How do I change the color of actionbar's up arrow?

How do I change the actionbar's up arrow. I am using the action bar in android not ABS or actionbarcompat. Is there a way to change the color /image of the action bar's up arrow ?
The answer is provided by Jake Wharton in How to customize the back button on ActionBar
<style name="Theme.MyTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">#drawable/my_up_indicator</item>
</style>
If you are using Toolbar, you can change the color by just changing the theme. You only have to change the style of the toolbar
app:theme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
If you are using a dark.actionBar your back button is going to be white else if you are using light actionbar theme it is going to be black.
Update:
If you want to modify the color as you wish (other then black or white) you can define a new style, parent one of the above themes and set colorControlNormal or android:textColorSecondary values to your desired color.
the actionbar's up arrow is an image.
you can change it by download a new one and replace it:
download new image,best is to download it from google material design icon page.download it in black or white in png format.save it somewhere you can find it easily.a good choice for download is the "navigate_before" icon .
insert the image to the studio: file->new->image asset. rename the image to your preffered name ( ic_back for example).
connect the up arrow button to the new image:
inside the values/styles.xml file add the item tag like that:
<style name="Theme.MyTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">#mipmap/ic_navigate_before</item>
</style>
I put the image asset inside the mipmap folder so I wrote "#mipmap" plus "/" and then the image name (mine was ic_navigate_before).
hope it helped!

Categories

Resources