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

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>

Related

Changing navigation back button icon dynamically doesn't work

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.

Change color of menu item and hamburger icon

I'm using the default drawerlayout template for an android app. The problem is that it comes out with white icons instead of black. How do I change that?
If you want to change the Android's generated Menu Icons like the Hamburger Icon and the menu item create a style like so:
<item name="android:textColorSecondary">#android:color/black</item>

Strange behavior of ActionBar home icon

I have 2 types of fragments between which I want to switch. Each time I create new instance of fragment I need.
In the first fragment I need to have clickable home icon so I set the appropriate (setDisplayShowHomeAsUpEnabled) display option to true and home icon starts look like an up. In the second one I don't need it so I set the appropriate display option to false and it stops looking as up. I'm listening to clicks on the action bar icon in parent activity.
The issue is that after second fragment is shown once the next time I show first fragment home icon remains clickable while it doesn't look like an up. The question is why is it clickable if currently visible fragment set it to not look like an up button?
I'm using appcompat-v7 library.
Please set the home buttom eanabled to false as well.
getSupportActionBar().setHomeButtonEnabled(false);
Lemme know if this works. :)
EDIT - One more way, but I am not sure on this.
You can set styles for your ActionBar title and over there you can set it as non-clickable as.
<item name="titleTextStyle">#style/TitleTextStyle</item>
and here is TitleTextStyle,
<!-- action bar title text -->
<style name="TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
<item name="android:clickable">false</item>
</style>
Remember to do this for support library as well. Try and see if it does the trick.

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