So this is what I have for my find_in_page.xml
<item android:id="#+id/find_text"
android:title="#string/find_text"
android:icon="#drawable/ab_search"
android:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.support.v7.widget.SearchView" />
<item android:id="#+id/find_next"
android:icon="#drawable/validation_arrow_inverted"
android:showAsAction="always"
android:title="#string/find_next"/>
<item android:id="#+id/find_prev"
android:icon="#drawable/validation_arrow"
android:showAsAction="always"
android:title="#string/find_prev" />
And my code:
public boolean onCreateActionMode(ActionModeCompat mode, Menu menu) {
mMenuInflater.inflate(R.menu.find_in_page_menu, menu)
}
Where mMenuInflater is an instance of android's menu inflater.
So the validation arrows come up fine but the searchview shows up in overflow menu and when I press it, it does not inflate.
How do I get the ab_search icon (its just a renamed magnifying glass icon) to show up in the menu and then expand to the text selection field?
Expand the SearchView with
searchView.setIconified(false);
and collapse it with
searchView.setIconified(true);
Related
I integrated cast to my app, and the default cast button color is black, but i'd prefer it white.
So I have 2 questions :
From what style does it taken from default ?
How can i change the style or color of the icon ?
Im using cast sdk v3.
I read the other related posts but they're all relevant to sdk v2.
this is my menu item layout as in google sample :
<item
android:id="#+id/media_route_menu_item"
android:title="#string/media_route_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"/>
this is the menu code to create the button :
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_podcast, menu);
mMediaRouteItem =
CastButtonFactory.setUpMediaRouteButton(getApplicationContext(),
menu,
R.id.media_route_menu_item);
return true;
}
Solution was simple as changing the activity theme to extend Theme.AppCompat instead of Theme.AppCompat.Light.DarkActionBar
Try to check the Customize App guide for Castv3 in Android. You can customize the colors, the overlay style, controller style, and more.
Customize Theme
The IntroductoryOverlay class supports various style attributes that your app can override in a custom theme. This example shows how to override the text appearance of both the button and title over the overlay widget:
<style name="CustomCastIntroOverlay" parent="CastIntroOverlay">
<item name="castButtonTextAppearance">#style/TextAppearance.CustomCastIntroOverlay.Button</item>
<item name="castTitleTextAppearance">#style/TextAppearance.CustomCastIntroOverlay.Title</item>
</style>
<style name="TextAppearance.CustomCastIntroOverlay.Button" parent="android:style/TextAppearance">
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="TextAppearance.CustomCastIntroOverlay.Title" parent="android:style/TextAppearance.Large">
<item name="android:textColor">#FFFFFF</item>
</style>
Here's what I have in my code:
#Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
if (MainActivity.fifty){
menu.findItem(R.drawable.fifty).setIcon(R.drawable.fiftyf);
}
return super.onCreateOptionsMenu(menu);
}
Now the thing is that when I delete if statement, then it works fine, but icon is not getting changed on the next activity.
Here's my xml file for menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/aud"
android:icon="#drawable/aud"
android:orderInCategory="1"
android:showAsAction="always"
android:title="Audience's Help"/>
<item
android:id="#+id/fifty"
android:icon="#drawable/fifty"
android:orderInCategory="2"
android:showAsAction="always"
android:title="50:50"/>
<item
android:id="#+id/friend"
android:icon="#drawable/friendhelp"
android:orderInCategory="2"
android:showAsAction="always"
android:title="Friend's Help"/>
As you can see, I just started to create icon changes. The idea is that the button is 50:50 for the game called "Who wants to be a millionaire". Now in the next activity, I am trying to set R.drawable.fiftyf, which is a disabled 50:50 icon, because when user uses it, it should not be available anymore.
When I tried to add it in menu.xml, then new icon was just added, which I don't need. Please also note, that icon gets changed according to my method, but app crashes when it goes to next activity.
Thanks all.
Please let me know if additional info required.
This is wrong:
menu.findItem(R.drawable.fifty).setIcon(R.drawable.fiftyf);
Should be something like this:
menu.findItem(R.id.fifty).setIcon(R.drawable.fiftyf);
I am following the tutorial on the developer website to implement an action menu bar, and I cant seem to get the icon to be drawn. http://developer.android.com/training/basics/actionbar/adding-buttons.html
Here is what I have so far...
res/menu/main_activity_actions
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:showAsAction="never" />
</menu>
Then I added that menu to the main activity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
I am pretty sure the icon can be found because I added it in all res/drawable-* folders
Then when I run the virtual device this is what I get
As you can see, the 2 menu items are there, but search has no icon like it does in the tutorial. Heres what it's supposedly supposed to look like
I have been going through the tutorials as well, and ran into the same difficulty. Here is what I found.
I spent a few hours trying the various technical solutions given for the problem. None of them made sense given my context. I tried a few things that seemed to suggest themselves to no avail. Then I found another possible solution, and although quite a bit simpler, perhaps harder to debug.
Make sure that the icons you provide are from the action bar icons in the path: holo_dark -> 01_core_search.
The holo_light icons were the same color as the background of my device and so appeared as if not present. Press on the screen in that area, and the icon does appear because the background color changes with selection of the menu item.
Hope this helps.
I tried to create a menu with search and refresh button, but since refresh button will only be available at several activities, I want to set the visibility to false, and then add this:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mainmenu, menu);
MenuItem item = menu.findItem(R.id.action_refresh);
item.setVisible(true);
return true;
}
to the activity java
Using the below code, the menu is displayed properly, with refresh on the left and search on the right
<item
android:id="#+id/action_search"
android:title="Search"
android:menuCategory="system"
android:orderInCategory="2"
android:showAsAction="always"
android:icon="#drawable/ic_action_search"/>
<item
android:id="#+id/action_refresh"
android:title="Refresh"
android:menuCategory="system"
android:orderInCategory="1"
android:showAsAction="always"
android:icon="#drawable/ic_action_refresh"
android:visible="false"/>
But by reversing the item order,
<item
android:id="#+id/action_refresh"
android:title="Refresh"
android:menuCategory="system"
android:orderInCategory="1"
android:showAsAction="always"
android:icon="#drawable/ic_action_refresh"
android:visible="false"/>
<item
android:id="#+id/action_search"
android:title="Search"
android:menuCategory="system"
android:orderInCategory="2"
android:showAsAction="always"
android:icon="#drawable/ic_action_search"/>
the refresh button/item will not appear.
While I have found the workaround and could proceed, this still puzzles me very much, and I haven't got any good explanation.
Why would that happen?
Are you using Eclipse?
I have seen a bug in Eclipse where simply changing the order of elements in an XML resource file would not recompile the file causing all kinds of weird things to happen.
I suggest you do a "Project > Clean" to make sure the resource identifiers get recreated from scratch.
I'm trying to enable users to change layout of my apps.
This is my XML:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menuTheme"
android:orderInCategory="1"
android:showAsAction="never"
android:title="Theme">
<menu>
<item
android:id="#+id/themeBlack"
android:title="Black" />
<item
android:id="#+id/themeWhite"
android:title="White" />
</menu>
</item>
<item
android:id="#+id/menuAbout"
android:orderInCategory="1"
android:showAsAction="never"
android:title="About" />
Here are the screenshots from my emulator:
This is my menu.
After clicking the item Theme under the menu, this submenu will appear.
Lets say i wish to add a white layout, where and how should i add codes?I have a XML file named themewhite.XML in the res/layout folder. I tried to add a switch in the item theme but it doesn't seemed to be correct.
This is my code:
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case R.id.menuTheme:
{
switch(item.getItemId())
{
case R.id.themeWhite;
{
setContentView(R.layout.themewhite);
}
}
break;
}
case R.id.menuAbout:
{
break;
}
}
return super.onOptionsItemSelected(item);
}
I guess you don't want to set new layout, you want change just visualisation of existing.
If so you should manilpuate with themes of your activity. For first you need to create themes (white and so on) and decalre views attributes with using values from style. And then in your listener after click one of items, you should change your theme by calling
getContext().setTheme(resid)
Here a good article about themes http://www.androidengineer.com/2010/06/using-themes-in-android-applications.html