ActionMode menu icon background - android

I am using the ActionMode via:
#Override
public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.menu_list_context, menu);
this.mActionMode = mode;
return true;
}
And my resource file menu_list_context is:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="#+id/discard_button"
android:icon="#drawable/ic_action_discard"
android:title="delete"
android:showAsAction="ifRoom" />
The style for my ActionBar is:
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#color/background_holo_light</item>
</style>
where <color name="background_holo_light">#dddddd</color>.
With these settings, my ActionBar under ActionMode looks like this:
The icon has the background of my ActionBar (holo light), but the ActionMode background seems white. How can I fix the icon background to have the ActionMode background (including the blue bottom line)?

You could try using the Action Bar Style Generator. This is the only way I know of to get exact ActionBar styles that actually works.

Related

Overflow Menu icon in Custom Toolbar

I am using a custom toolbar which has a menu icon. Now on clicking this menu icon i want to show the options menu. How can this be done.
I tried adding a onclicklistener to this menu icon
#Override
public void onClick(View v) {
if(v.getId() == R.id.toolbarMenuIcon){
openOptionsMenu();
}
}
This didnt work. Then i added these lines
setSupportActionBar(mBinding.customSelectToolbar.selectionModeToolbar);
in my activitys oncreate() . Also did override
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.selection_mode_menu, menu);
return super.onCreateOptionsMenu(menu);
}
With this i can see the overflow menu when i click the icon. But the problem is that, it adds the default menu icon also to the tool bar and thus my tool bar has two menu now. How can i have only my custom toolbar icon open the options menu
If you want to customize the default overflow menu icon..
Use setOverflowIcon method of your toolbar.
like:
toolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.your_icon));
I got it working using theme
<style name="OverFlow" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">#drawable/ic_menu_overflow</item>
<item name="android:tint">...</item>
<item name="android:width">..dp</item>
<item name="android:height">..dp</item>
</style>
<style name="OnArrival.toolbarTheme" parent="Theme.OnArrival.Light">
<item name="actionOverflowButtonStyle">#style/OverFlow</item>
</style>

Contextual action bar not overlapping toolbar completely

I'm adding contextual action bar after long click of RecyclerView element. Problem is toolbar is still visible. Contextual action bar doesn't overlap completely.
Tried searching for info, but no or very little info found.
My toolbar:
After adding contextual action bar:
As you can see toolbar is still visible at the bottom.
Theme im using:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
</style>
My toolbar:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:minHeight="?android:attr/actionBarSize"
android:background="#F7F8F9"
app:titleTextColor="#color/colorPrimaryDark" />
cab.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_upload"
android:title="Upload"
android:icon="#drawable/ic_file_upload_black_24dp"
app:showAsAction="always" />
<item
android:id="#+id/action_reboot"
android:title="Reboot"
android:icon="#drawable/ic_refresh_black_24dp"
app:showAsAction="always"/>
</menu>
This is how i'm starting Contextual action bar:
startSupportActionMode(new android.support.v7.view.ActionMode.Callback() {
#Override
public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.cab, menu);
return true;
}
#Override
public boolean onPrepareActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(android.support.v7.view.ActionMode mode, MenuItem item) {
return false;
}
#Override
public void onDestroyActionMode(android.support.v7.view.ActionMode mode) {
}
});
My readings:
contextual action bar padding in Android
Contextual action bar does not overlay my toolbar
Tried pretty much everything from questions above. None of them have helped.
P.S. Tried increasing/decreasing size of the toolbar, but visible line is still visible
So how to make Contextual action bar overlap toolbar completely?
Add
<item name="actionModeBackground">your_color</item>
in your styles.xml file, it will overlay your toolbar completely.

Menu item goes in dropdown list menu not in the action bar

Hello
I'm trying to add 2 menu items in the action bar. On the designer they look ok, but when I run the application, both menu items goes in the dropdown list hamburger menu (there's enough "room" to display on the action bar).
I tried to replace app:showAsAction to android:showAsAction, doesn't work this replacement.
this is my menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.tabdemo.MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title=""
app:showAsAction="never"
/>
<item
android:id="#+id/userMenu"
android:title="User"
app:showAsAction="ifRoom" />
<item
android:id="#+id/logoutMenu"
android:icon="#drawable/opendoorlogo2"
android:title="Logout"
app:showAsAction="ifRoom" />
And this is the java code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
MenuItem userMenuItem = menu.findItem(R.id.userMenu);
userMenuItem.setTitle(username);// global string
MenuItem logoutMenuItem = menu.findItem(R.id.logoutMenu);
logoutMenuItem.setIcon(R.drawable.opendoorlogo2);
return true;
}
Thanks in advance (P.S. Logo doesn't load on Logout menu Item)
First of all make sure your drawable file is not too big for the actionbar, if so you can convert it to actionbar icon size.
https://romannurik.github.io/AndroidAssetStudio/icons-actionbar.html#source.space.trim=1&source.space.pad=0&name=ic_action_example&theme=light&color=33b5e5%2C60
android:showAsAction="always"
if this doesn't help you.
Best way is to create a custom actionbar layout and place your icon over there instead of adding it as Menus.

Increasing ActionBar's height but Action-Icons don't occupy that height

I can increase the ActionBar's height to its double size (by Default is action_bar_default_height = 48dp standard ActionBarSize), so, 96dp but the Icons of my ActionBarare just as little as with standard height.
In order to acquire a better understanding, I illustrate with a Picture.
Can anyone tell me, why I get left Icons properly but the associated Icons to Actions not?
How could I solve it?
That's my code
First, I define the proper ActionBarSize Height and set the proper Size through Themes-Styles of my Activity in my styles.xml like this
<style name="Theme.ActionBarSize" parent="android:Theme.Holo.Light">
<item name="android:actionBarSize">96dp</item>
</style>
Second, I declare that Theme in the proper Activity in my Manifest File
<activity android:name="com.nutiteq.advancedmap.activity.WmsMapActivity"
android:theme="#style/Theme.ActionBarSize" >
Third, I create an ActionBar Instance and I initialize it properly in onCreate Method of my Activity
...
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.show();
...
Fourth and last one, I inflate the associated Action-Items of ActionBar in onCreateOptions(...) Method like this
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.wms_context_menu, menu);
return true;
}
My ActionBar Items are defined in the file wms_menu.xml which looks like as follows
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/videonotes"
android:showAsAction="ifRoom"
android:title="#string/vid_description"
android:icon="#drawable/ic_action_video_96" >
</item>
<item android:id="#+id/textnotes"
android:showAsAction="ifRoom"
android:title="#string/txt_description"
android:icon="#drawable/ic_action_edit_96" >
</item>
<item android:id="#+id/picnotes"
android:showAsAction="ifRoom"
android:title="#string/pic_description"
android:icon="#drawable/ic_action_camera_96" >
</item>
<item android:id="#+id/audionotes"
android:title="#string/aud_description"
android:showAsAction="ifRoom"
android:icon="#drawable/ic_action_pic_96">
</item>
<item android:id="#+id/right_drawer"
android:title="#string/right_slide_description"
android:showAsAction="ifRoom"
android:icon="#drawable/ic_drawer_96" >
</item>
</menu>

android search view icon color changing programmatically

How do I change the Android search view icon color? By default color is white, is it possible to change the icon color.
I have tried:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/action_search"
android:actionViewClass="android.widget.SearchView"
android:icon="#drawable/ic_theme_blue_menu"
android:showAsAction="always"
android:title="#string/search_actionbar"/>
<item
android:id="#+id/slider_menu"
android:icon="#drawable/ic_slider_menu"
android:orderInCategory="100"
android:showAsAction="always"/>
</menu>
But I need to change it in code, not in the layout file. Is it possible?
Unfortunately, there is no easy way to change the SearchView icon to a custom drawable, since the theme attribute searchViewSearchIcon is not public. Check this answer for details.
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>
What I do, I have create a method to change any drawable color
public Drawable changeDrawableTint(Drawable drawable, int color){
final Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTintList(wrappedDrawable, ColorStateList
.valueOf(color));
return wrappedDrawable;
}
, even in android versions pre lollipop, then I get the search view menu item, and call the method with the desired color
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
/**
* We inflate the correct activity menu
*/
getMenuInflater().inflate(R.menu.menu_partner_list, menu);
searchViewMenuItem = menu.findItem(R.id.action_search);
if(searchViewMenuItem!=null && searchViewMenuItem.getIcon()!=null){
searchViewMenuItem.setIcon(Utils.getInstance()
.changeDrawableTint(searchViewMenuItem.getIcon(),
Color.WHITE));
}
setUpSearchView(menu);
shouldHideMenuActions();
return true;
}
here is the menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always|collapseActionView"
android:icon="#drawable/ic_search"
android:title="#string/search" />
</menu>
you could use the following code in your java class:
mView.getBackground().setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.LIGHTEN);
This line above changes the color of the view to to a share of color you suggest in Color.parseColor() and a shade like how you define it using PorterDuff.Mode. Call the above code on click of a button to check if the color change is taking effect.

Categories

Resources