Search View Change Search Menu Item image - android

When using the theme Theme.Sherlock.Light
and using a searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/location_search_hint"
android:icon="#drawable/action_search"
>
</searchable>
I expect the Search icon to take my own #drawable/action_search which is white but it's ignoring it and it takes the one from the light theme.
How would I be able to change that?

So well, I think I found a solution for your problem.
Add this line to your themes.xml
<item name="searchViewSearchIcon">#drawable/menu_search</item>
There you can "overwrite" the styles like the magnifier icon with your own drawables.
You may also use the other styles like
<item name="searchViewCloseIcon">#drawable/menu_search_close</item>
etc.
Hope this helps,
Tobias

Note the menu needs to have the collapseActionView attribute
android:showAsAction="ifRoom|collapseActionView"
Source
EDIT:
Actually I found a better solution
the Menu can keep the following line:
android:showAsAction="ifRoom"
And the icon for the search need to use the same name as the one from ActionBarSherlock/AppCompat/Native
for app compat it would be abc_ic_menu_share_holo_dark.png

Related

Changing the Color of the the Menu Items does not work

I have created a menu and now I want to change the text color of the individual menu titles.
To do this, I first created a style that should contain the corresponding attribute and then called this style in my Activity_home_drawer.xml. However, this only changes the menu TextColor when the corresponding menu title is clicked but is not permanent as I would like it to be.
What do I have to do so that the text color in my menu changes permanently to white and not Black anymore? Is my way of doing it the right way or is there a more elegant way to change the TextColor?
Thanks for any help!
Part of my Activity_home_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view"
android:theme="#style/TextAppearance44">
<group android:id="#+id/category_group">
<item
android:id="#+id/nav_menu"
android:icon="#drawable/ic_store_black_24dp"
android:title="#string/menu_menu"
android:theme="#style/TextAppearance44"
/>
</group>
My TextAppearance44 style
<style name="TextAppearance44">
<item name="android:textColor">#color/colorWhite</item>
<item name="android:actionMenuTextColor">#color/colorWhite</item>
<item name="android:textSize">16sp</item>
<item name="android:titleTextColor">#color/colorWhite</item>
</style>
You need to change your ToolBar style. Check these two tutorials:
Toolbar assigning to activity and styling:
https://android-developers.googleblog.com/2014/10/appcompat-v21-material-design-for-pre.html?m=1
Changing style and items colors in the Toolbar:
https://www.murrayc.com/permalink/2014/10/28/android-changing-the-toolbars-text-color-and-overflow-icon-color/
In your case, you are looking mainly for (code fragment from second tutorial):
<!-- android:actionMenuTextColor is the color of the text of
action (menu) items in the Toolbar, at least in the
Theme.AppCompat theme.
For some reason, they already get the textColorPrimary
when running on API 21, but not on older versions of
Android, so this is only necessary to support older
Android versions.-->
<item name="actionMenuTextColor">#color/abc_primary_text_material_light</item>
I solved it by myself; I added these to lines to my NavigationView in my ActivityHome (where the Menu comes up).
app:itemTextColor="#color/colorWhite"
app:itemIconTint="#color/colorWhite"
Simple mistake, didnot know that there was such a attribute.

Remove SearchOrbView Android TV

How can I remove the searchOrbView in the BrowseFragment of Android TV?
I see a way to set the colors (setSearchAffordanceColors), but no way to actually remove the SearchOrbView
Since the TitleView is a private member of BrowseFragment (and TitleView is the way to get to the SearchOrbView), I see no way of actually removing the SearchOrbView
According to the official documentation, calling setOnSearchClickedListener() causes the search orb to be displayed in the title view.
Removing the method invocation will make the orb disappear.
For those who doesnt read comments
you can simply achieve that defining a new style with Theme.Leanback.VerticalGrid as parent and setting item browseRowsMarginTop to any dp value you need. Then set this theme for the Activity implementing the vertical grid view. – fasteque
It helped me.
style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#style/Theme.Leanback"></style>
<style name="NoTitleTheme" parent="#style/Theme.Leanback">
<item name="browseRowsMarginTop">5dp</item>
</style>
</resources>
AndroidManifest.xml
....
<activity
android:name=".stackedadprogram.StackedAdProgramActivity"
android:exported="true"
android:parentActivityName=".launcher.ProgramDetailActivity"
android:theme="#style/NoTitleTheme" />
....

Customizing Up/Back/Burger background in my ActionBar

I'm trying to customize the background of my action bar items with a selector, to override what is shown when the button is pressed.
This was pretty easy with menu buttons (e.g., overflow icon), as you can style them with actionBarItemBackground .
Sadly this does not apply for the up/home/left indicator. I have unsuccessfully tried, in my styles.xml:
<item name="actionButtonStyle">;
<item name="actionBarStyle">;
<item name="toolbarStyle">;
None of the nested attributes seem to act on the home icon background. I also searched over android.R.attr and gave a look at this. Is there any way?
I would like to stay with the "up" indicator, without inflating a custom view. In that case, I would also have to inflate the title as well as custom views naturally appear at the end of the title. AND I would lose the burger-to-arrow animation, AND I would have to take care about margins and design guidelines (now managed by AppCompat), and some other bad thing on the way.
I thought about setting a Logo, but that would have some complications as well and I don't think I could change the background anyway.
I thought about Toolbar being a Layout, so I could put custom views in it from XML. If I'm not wrong they appear after the title, so neither this is a good idea.
What can I do?
please let me know if it works
add this to your your theme or if it doesn't take both remove the one with android prefix
<item name="android:selectableItemBackground">#drawable/selector</item>
<item name="selectableItemBackground">#drawable/selector</item>
Example #drawable/selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#ddffffff" />
<item
android:drawable="#android:color/transparent" />
</selector>

Android Menu Bar

I have created a sample android application that just displays some text and i can see that the menu bar at the top of the activity contains name of the application but not the icon of the application. The menu is also very thin just containing application name with a small font. Going through various tutorial i found that we have to select a particular menu style while creating the application to have a menu that contains both application name and icon, but my application just contains application name and the menu is very thin. Is it possible to increase the menu height now and add application icon to it dynamically or by making some changes in menu xml file?
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/app_name" android:icon="#drawable/ic_launcher"
android:title="My App" />
</menu>
If you want to customize the ActionBar, here you are a complete tutorial for it:
How can I implement custom Action Bar with custom buttons in Android?
It's very good an complete for customizing almost everything, so I recommend it to you.
Even tough, I ask you to change your question in order to make more clear the target of it, now you know what you were triying to mean ;)
<menu xmlns:tools="schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="com.example.sample.getMsgActivity"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<!-- Search, should appear as action button -->
<item android:id="#+id/action_write"
android:icon="#drawable/ic_action_refresh"
android:title="#string/action_write"
yourapp:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_read"
android:title="#string/action_read"
yourapp:showAsAction="never" />
REMEMBER: clean, then build. it should work then.

Text or Icon in action bar, stuck with the 3 dots

I'm making an android app in Eclipse. I want to place a text or icon in the action bar, but when I am writing in menu.xml, which looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/createnew"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:title="CREATE"/>
</menu>
it puts it in the options menu. I want to separate it.
I see this in the app when I run it:
(sorry can't post pictures because I don't have enough rep)
I want to CREATE next to the option menu like this for example:
Since you are using the AppCompat Actionbar, you need to use a custom namespaced showAsAction attribute.
It should look something like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/createnew"
android:orderInCategory="1"
yourapp:showAsAction="ifRoom"
android:title="CREATE"/>
</menu>
Note that this uses yourapp:showAsAction instead of android:showAsAction. This is because the showAsAction attribute is not available on pre-Honeycomb devices and is provided by the support library.
For more information, read the Action Bar developer guide.
It's caused by this line
android:showAsAction="ifRoom"
That tells Android to put it up there if it's going to fit nicely. If you want it up there no matter the fit use
android:showAsAction="always"

Categories

Resources