I'm using ActionBarSherlock and creating a custom ActionProvider. When clicking on the custom action provider, I've managed to make the topmost LinearLayout clickable and set a custom selector on it.
The problem is that compared to simple menu item with an icon, the custom action provider doesn't use the selector to highlight the action bar entirely from top to bottom. A few pixels on top and bottom are not being highlighted.
There is probably an elegant solution to make the entire custom action provider behave like a simple clickable menu item with an icon. Any help will be greatly appreciated.
I figured it out. Instead of using an Action Provider, I used the actionLayout for the menu item and made it clickable as shown in this post.
Related
I need to develop a custom layout for the action bar in Android.
I'm now stuck because I have no clue how to calculate the available space for my custom layout.
In the image, the red part is my custom layout, the blue part is the space occupied by the action buttons.
Clearly I need to know/calculate the size of the red part to be able to correctly position the elements in my custom action bar (for example center the title in the window or make sure not to overflow in the blue part).
How can I achieve this?
I couldn't find useful examples or a clear API in the Android documentation.
I think that anyone using the custom action bar layout must be facing this kind of problem, I'm a bit confused.
Or am I supposed not to use action buttons in this case? Perhaps I'm supposed to replicate the action buttons by myself?
Thanks in advance
Try using ToolBar instead of ActionBar. It will give you a lot more control over ActionBar elements than ActionBar.
Here is a simple tutorial about how to replace ActionBar with ToolBar and how you can customise it.
Material ToolBar
Possibilities are endless with ToolBar but my recommendation is to don't overdo anything.
As per my suggestion try to use the entire action bar by your custom layout. So that you can arrange all the things use it as a fragment inside a framelayout for all your screens so that the code can be reused for all your layouts.
I am working on an Android application where I have to design a menu which will populate from the action bar, like this:
I have tried my best but was not able to produce it using the Android controls.
The solutions I have tried are:
With Actionbar, add a menu item with a group with selectable="all", that produces the layout I need but when I click a checkbox for selecting it, the whole menu hides and selection is not done, moreover the menu icon in actionbar does not have the bottom right white arrow.
Tried creating a custom ActionProvider and added the menu items using class's OnPrepareSubMenu method but had the same issue.
I just need a push in the right direction and I can do the rest, suggestions are more than welcome.
Thank you :)
Use popupWindow.
In that you can make any custom layout and set it as content of your popupwindow and also you can specify an ANCHOR in your case it would be
R.id.your_menu_item
set a listener and listen the changes.
I'm trying to make a feature where there's a button on the bottom action bar, and once I click on it, a progress bar appears on top of the button and makes the button slightly transparent (not disappear).
I used a custom layout for the top action bar, so on the bottom action bar, I wrote it through menu.xml since I've hard I couldn't have a second custom layout. I was wondering if this feature was possible just from the menu item properties.
Is it possible to make some form of like a frame-layout just from the menu.xml?
I'm assuming you're using a split action bar (uiOptions="splitActionBarWhenNarrow"), so that the custom layout you use is on the top with the application icon? The bottom bar is the menu items contained in an XML?
If this is the case, you can specify a custom layout for a menu item by using the layout attribute on the item. You could make a layout which has both items on top of each other (initially the button is VISIBLE with no alpha and the progress is GONE), then set up a click handler on the item in the onPrepareOptionMenu to set the alpha on the button to make it semi-transparent and change the visibility of the progress bar to VISIBLE.
I believe in the case where you use a custom layout, you can't use the id of the menu item for click handling (onMenuItemClicked), so you'd have to register a click listener either programatically or through the XML onClick attribute.
I apologize if any of the API calls are not 100% correct. I'm doing this mostly from memory.
I would like to create an simple menu type Action Bar along the top. I like using buttons, but need the color or image to change and hold when on selected link. Or else, could a radio button be used as an alternative to Action Bar? I would like it to look like the menu tabs on this screenshot link: view link hereThank you!
According to Jake as in Android layout with action bar and tabs, we decide to follow his 2nd suggestion.
Use tab navigation in the action bar and set a custom view with a Spinner
Together with IcsSpinner from ActionBarSherlock itself, we manage to make it work in Gingerbread and ICS both.
However, we still suffer the following problem, during landscape mode.
Note, the spinner ("Portfolio 1") is in between PORTFOLIO tab and search icon. What we want is, the spinner is at the left side of WATCHLIST tab.
Is there anything we may try out?
Thanks.
You can set custom view for your action bar, user RelativeLayout to put your spinner at left side of "WATCH LiST"
in java code: actionBar.setCustomView(R.layout.custom_actionbar_layout)
a very late answer, but this is possible. You just have to replace (programatically) the view that is pointed by android.R.id.action_bar_title with a Spinner. I wrote a blog about it. Here's the link