How to make an icon in a style clickable? - android

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()

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.

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.

ActionBar - Using a View as icon

So, I want to use a View in place of the app icon in the actionbar. I can't use a simple image because the View will change its colours depending of the set of colors chosen in the parameters of the app (and I don't want to create four hundred images in photoshop...).
I know I can use a custom view for the action bar and it's even quiet easy, but the problem is that the original app image is still shown. I also know that I can hide it by setting setDisplayShowHomeEnabled to false, but that also hides the glyph of my navigation drawer and that is the problem.
I also tried to create a custom Drawable and override the onDraw method but nothing was shown and the Drawable has 1px height/width.
To hide the icon you can use a transparent one, edit the style you use for your actionbar like this :
<style name="MyActionBarStyle" parent="#style/Widget.Sherlock.Light.ActionBar">
<item name="icon">#android:color/transparent</item>
</style>
assuming you use as style named MyActionBarStyle for your actionbar in your theme.
<style name="AppBaseTheme" parent="#style/Theme.Sherlock.Light">
<item name="actionBarStyle">#style/MyActionBarStyle</item>
</style>

How to change SearchView default icon?

I've used "Android Action Bar Style Generator" in order to generate my own Holo theme.
Then I've added two icons to the action bar, one for a searchFilter and one for a file picker, both icons are white. File picker icon (at the right) looks good, but somehow search icon looks dark grey. When typing on the search text view, close button also looks dark grey.
I've tried changing color of the actionbar and also from the searchview, without success. Why is the search view showing this color? How can I change it?
Thank you very much.
UPDATE: I thought that my app was using my icon but it doesn't, it uses the default search view icon, so my question actually is, how do I change the default icon of the search view?
This sentence at the menu.xml file is not working:
android:icon="#drawable/selectable_header_search"
Unfortunately, there is no easy way to change the SearchView icon to a custom drawable, since the theme attribute searchViewSearchIcon is not public. See this answer for details.
However, I think that your problem is caused by inheriting from the wrong theme. Please use android:Theme.Holo.Light.DarkActionBar as the base for your theme. Then the default icons on the action bar should have a light color.
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
...
</style>
Since the searchViewSearchIcon attribute is not public, you can change the icon using the following code:
int searchIconId = searchView.getContext().getResources().getIdentifier("android:id/search_button",null, null);
ImageView searchIcon = (ImageView) searchView.findViewById(searchIconId);
searchIcon.setImageResource(R.drawable........);
Try to set up in the showAsAction this option: *MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW*
Without this option the SearchView do not take the icon which you setup for action button.
menu.add("Search")
.setIcon(
getResources().getDrawable(
R.drawable.selectable_header_search))
.setActionView(searchView)
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS
| MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
| MenuItem.SHOW_AS_ACTION_WITH_TEXT);
The easiest way I've found to change the default searchview icon in the action bar is in your onPrepareOptionsMenu. You can see my answer here to a similar question!
In your theme style include this:
<style name="YourTheme.Toolbar">
<item name="searchViewStyle">#style/YourActionBarSearch</item>
<item name="editTextColor">#color/your_ab_text_color</item>
<item name="android:textColorHint">#color/your_ab_hint_color</item>
</style>
You can now define the style of the SearchView with searchViewStyle, and editTextColor will set the color of the text in the search box. By setting android:textColorHint you will also set the color of the hint, e.g. "Search...".
<style name="YourActionBarSearch" parent="#style/Widget.Holo.SearchView">
<item name="searchIcon">#drawable/ic_ab_search</item>
<item name="queryBackground">#null</item>
<item name="submitBackground">#null</item>
<item name="searchHintIcon">#drawable/ic_ab_small_search</item>
<item name="defaultQueryHint">#string/toolbar_search_hint</item>
<item name="closeIcon">#drawable/ic_ab_small_search_close</item>
</style>
This will style your search view as you like, more or less. The field searchIcon is the icon in the action bar. The field searchHintIcon is the small icon to the left of the hint in the search field. The field closeIcon is the close icon at the right side of the search field.
Check this out, for more style settings:
$ANDROID_SDK/platforms/android-24/data/res/values/styles_holo.xml
For those like me hoping to find a way to truly change the icon, you can use this with actionbar sherlock:
// Getting the 'search_icon'
ImageView searchIcon = (ImageView)searchView.findViewById(R.id.abs__search_button);
// Setting background of 'search_plate' to earlier defined drawable.
searchIcon.setImageResource(R.drawable.search_button_selector);
You can't change the default one with the common way android:icon, because the field related to it had been set to private.

Categories

Resources