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

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>

Related

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.

ActionBarSherlock narrow items in ActionBar are not centered

I'm using actionbarsherlock library, activity has flag android:uiOptions="splitActionBarWhenNarrow", so ActionBar's items are in the bottom of screen
the items are described in the xml file
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_0"
android:title="#string/action_0"
android:showAsAction="always"/>
<item android:id="#+id/menu_1"
android:title="#string/action_1"
android:showAsAction="always"/>
<item android:id="#+id/menu_2"
android:title="#string/action_2"
android:showAsAction="always"/>
</menu>
I'm inflating menu
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
MenuInflater supportMenuInflater = getSupportMenuInflater();
supportMenuInflater.inflate(R.menu.inbox_conversation, menu);
return super.onCreateOptionsMenu(menu);
}
after, on devices with android 2.3, menu items do not have the same weight
first two options take about 80% percents of action bar & the latest takes only 20%, so they are not aligned properly & don't take equal space.
Don't know what to do. Any suggestions?
Many thanks!
might want to try adding layout-weight in item tag in xml
<item
android:id="#+id/menu_0"
android:title="#string/action_0"
android:showAsAction="always"
android:layout_width="wrap_content"
android:layout_weight="1" >
</item>

action bar showing large space between app icon and menu items

My action bar shows the app icon on the left, then has a large space, and then shows some of my menu items on the right (the rest go into overflow). The problem is that the "large space" is big enough to hold several more icons. Why isn't it being used?
My menu resource looks like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_a"
android:icon="#drawable/a"
android:title="a"
android:orderInCategory="100"
android:showAsAction="ifRoom" >
<menu>
<item ... />
...
</menu>
</item>
...
<item
android:id="#+id/menu_n"
android:icon="#drawable/n"
android:title="n"
android:orderInCategory="100"
android:showAsAction="ifRoom" >
...
</item>
</menu>
In my Activity, I have:
#Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView (R.layout.main_activity);
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setHomeButtonEnabled (true);
...
}
and
#Override
public boolean onCreateOptionsMenu (Menu menu)
{
getMenuInflater().inflate(R.menu.nav_menu, menu);
return true;
}
I have a suspicion it has something to do with the app title (setDispalyShowTitleEnabled), which I have disabled. Maybe I'm doing it wrong?
Nothing wrong with your code.
AtionBar by default allows only 2-3 menu items even when there is enough room to accommodate 4-5.
May be to maintain better UI.
So, instead of
android:showAsAction="ifRoom"
use
android:showAsAction="always"
to have the MenuItems always present on the ActionBar instead of going into the overflow menu.

Using a selector for a MenuItem in the ActionBar

I'm using ActionBarSherlock. I have a MenuItem, and I want to use a custom selector with only that MenuItem, not the others in the ActionBar. This is the menu code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_include_location"
android:icon="#drawable/icon_place_selector"
android:showAsAction="always"
android:title="#string/menu_include_location"/>
<item
android:id="#+id/menu_send"
android:icon="#drawable/ic_send"
android:showAsAction="ifRoom|withText"
android:title="#string/menu_send"/>
</menu>
Here is the icon_place_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/location_place" android:state_pressed="false"/>
<item android:drawable="#drawable/location_no_gradient" android:state_pressed="true"/>
</selector>
The issue is that in the MenuItem, the icon is only a small part of it. Here's a screenshot of what shows up. The entire background should change, and not just the icon. How do I do that?
You can change the selector of a particular action bar item by setting a custom ActionView in the code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
MenuItem menuItem = menu.findItem(R.id.menu_include_location);
ImageView image = new ImageView(this);
image.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
image.setPadding(16, 0, 16, 0);
image.setImageResource(R.drawable.ic_launcher);
image.setBackgroundResource(R.drawable.icon_place_selector);
image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// ...
}
});
menuItem.setActionView(image);
return true;
}
Apply these styles if you want to change the selector for all action bar items:
<style name="AppTheme" parent="#style/Theme.Sherlock">
<item name="android:selectableItemBackground">#drawable/icon_place_selector</item>
<item name="android:actionBarItemBackground">#drawable/icon_place_selector</item>
</style>
Use Actionbar style generator, to style your style and download zip file
In downloaded zip file open selectable_background_xxxx.xml (xxxx -> name given to your own style) file in "drawables" folder and change the drawable to nine-patch img or color code you want when pressed state is true.
<item android:state_pressed="true" android:drawable="#color/your_color" />
first you shall know, if you set android:selectableItemBackground in your holo style, the whole widget, i.e. a button, will have that background selector.
if you just need to change your actionbar menuitem' s icon selector background, Here is a simple answer!
just set android:actionBarItemBackground in your holo style!
<style name="AppTheme.Dark" parent="android:Theme.Holo">
<item name="android:actionBarItemBackground">#drawable/item_background_holo_light</item>
</style>
hope it helpful:-)

ActionBar not being created even with min SDK version set to 11

I have my min SDK version set to 11 and my target SDK version set to 11. I have an activity with some fragments in it. The style has parent="#android:style/Theme.Light" and doesn't hide the actionbar. In the activity where I expect to see the actionbar, I have an override of onCreateOptionsMenu(). My understanding is that onCreateOptionsMenu() will automatically be called when the activity starts and that will create the actionbar. This is not happening for me. I'm not sure if my understanding is wrong or if I'm doing something wrong that is causing it not to show up.
To be clear, my onCreateOptionsMenu method is not even firing. I suspect the problem is in another part of the code, but I don't know what it could be.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.signin_layout_menu, menu);
return true;
}
Here is my menu xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_signin_layout"
android:title="stuff"
android:showAsAction="ifRoom|withText" />
</menu>
Here is the style that activity is using:
<style name="Theme.MyTheme" parent="#android:style/Theme.Light">
<!-- Window attributes -->
<item name="android:windowTitleSize">36dip</item>
<item name="android:windowTitleStyle">#style/WindowTitle</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
<item name="android:textAppearanceButton">#style/TextAppearance.Widget.Button</item>
<!-- Button styles -->
<item name="android:buttonStyle">#style/Widget.Button</item>
</style>
I'm pretty sure your theme needs to be parent="#android:style/Theme.Holo.Light" for the actionbar to show.
Are you inflating the menu and returning "true", to indicate that you've handle the action, correctly in your onCreateOptionsMenu() override? http://developer.android.com/guide/topics/ui/menus.html#Inflating
If you're returning false, the event will bubble up to the parent, which by default does nothing.

Categories

Resources