ActionBar's action items not working on some devices - android

I'm developing an app using ActionbarSherlock for backwards compatibility, and I'm currently having problems with the Spinner I add to the ActionBar.
Scenario:
I'm using ActionBar.NAVIGATION_MODE_TABS and each tab is a Fragment with it's own inflated menu.
I have no problem inflating and populating the menus or Spinners, but the problem is that the Spinner is not expanding when a user clicks it. However, when the user slides to another fragment the Spinner expands (and is shown in the wrong fragment), and when sliding back again the Spinner works as expected in the correct fragment.
This problem only occurs on devices <4.0.x (haven't tried 3.x). When testing on >4.0.x it works as expected.
I have tried debugging and going through callback methods, but I can't figure out why this happens. Can it be a bug in older versions of Android, or is it because menus and such are handled differently? (shouldn't though since I'm using ActionbarSherlock).
Does anyone have an idea of why this is happening?
EDIT:
I noticed that the problem occurs to the fragments/tabs that are not added first to the ViewPager, no matter what action item is in the menu. The first tab, i.e. the one that is active once the Activity starts, never has this problem.
Is it just me who is missing something, or is this how it's supposed to be?

Try this, It might help you
For spinner
<com.actionbarsherlock.internal.widget.IcsSpinner
android:id="#+id/spinner_id_name"
style="#style/your_style_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:scrollbars="none" />
In style.xml you apply this
<style name="your_style_name">
<item name="android:dropDownWidth">fill_parent</item>
<item name="android:background">#drawable/spinner_background</item>
<item name="android:popupBackground">#drawable/spinner_dropdown_background</item>
<item name="android:divider">#color/gray_darkest</item>
<item name="android:alignmentMode">alignBounds</item>
<item name="android:dividerHeight">2dp</item>
<item name="android:scrollbars">none</item>
<item name="android:scrollbarAlwaysDrawVerticalTrack">false</item>
<item name="android:scrollbarTrackVertical">#android:color/transparent</item>
<item name="android:dropDownSelector">#android:color/holo_dark</item>
<item name="android:requiresFadingEdge">none</item>
</style>

I had a very similar problem. In my case the Activity was extending another one and the "parent" activity was returning false in onPrepareOptionsMenu() function. This was causing wrong behaviour on Android 2.x, on Android 4 all was OK. When I changed the code to return true all is fixed. Another very strange thing I noticed was that the non-working ActionItem icons where darker then the good ones (in another Activity).

Related

Adding a dropdown menu from a click event in the action bar in xamarin forms android

I added a toolbar item in my content page:
<ContentPage.ToolbarItems>
<ToolbarItem IconImageSource="icon_dropdown.png"/>
</ContentPage.ToolbarItems>
What I want to have is when a user clicks on the toolbar item, a menu pops down like this. Animated in a way where it slides down revealing the content/menu items.
I've been searching online but the keywords being searched always takes me to spinner, and being new to C# and Xamarin Forms, I am unsure if a spinner is still what I want to achieve something like this because a spinner looks more of a dialog box.
Sample image of what I'm trying to do that I've photoshopped
Any help is highly appreciated. Thanks.
I did some investigation, and find a way to change the position of the overflow popmenu by theme(code attached at the end in case you need it), but unable to change the width to match the whole screen, not sure if Android made some limitations in menu.
If you need a drop down list exact the same of your picture, spinner may not be a perfect choice either, you'd better create a new activity that overlays origin activity and customize the new activity layout, but it's not recommended considering performance. Also, you can find something in an earlier post to see if it gives you any idea.
add a new style:
<style name="OverflowMenuStyle" parent="#style/ThemeOverlay.AppCompat.Light">
<item name="overlapAnchor">false</item><!--not overlay the toolbar-->
<!--<item name="android:dropDownWidth">10dp</item> not work-->
<!--<item name="android:maxWidth">400dp</item> not work-->
<item name="android:paddingRight">0dp</item>
<!--dropDownVerticalOffset is the property you want to avoid overlay the toolbar-->
<item name="android:dropDownVerticalOffset">4dp</item>
<item name="android:dropDownHorizontalOffset">0dp</item>
<item name="android:popupBackground">#BFBFBF</item>
</style>
Android Resource layout folder's Toolbar.xml, change popupTheme to:
android:popupTheme="#style/OverflowMenuStyle"
add an item in MainTheme.Base style:
<item name="actionOverflowMenuStyle">#style/OverflowMenuStyle</item>

Android M: options menu background disappears

Faced a strange options menu behavior on Android M.
Menu shadow is implemented with 9 patch and works perfect on previous Android versions.
But on sixth Android it appears only for a while.
Also it look like it appears for a while during close animation.
Menu style is below:
<style name="PopupMenu" parent="Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#drawable/shadow</item>
<item name="android:overlapAnchor">true</item>
</style>
Will be thankful for any help in fixing this shadows visibility issue.
Try to remove background from DropDown ListView style

Android menu item showAsAction="always" doesn't work

I have tried setting the:
android:showAsAction=".."
to every one of these:
ifRoom, never, withText, always, collapseActionView
but I always got the same result, which is not having any buttons on the action bar, so I have to press the 'menu' button.
Here is a picture of the menu now :
<item android:id="#+id/smth1"
android:title="#string/smth1"
android:showAsAction="always"
android:orderInCategory="1" />
I have even tried adding this:
android:uiOptions="splitActionBarWhenNarrow"
into application manifest file, but with no positive result (nothing changed).
I have tried running it on various kind of APIs (14, 16, 17, 19), but with the same result.
If my question seems to be unclear, here is a picture of a menu, which I would like to have:
Thanks for any help.
You need to use the compatibility namespace (see here)
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_add_size"
android:title="#string/menu_add_item"
android:icon="#android:drawable/ic_menu_add"
app:showAsAction="always"/>
</menu>
Once you're using that you can use as many menu buttons as will fit. You're no longer limited to just two buttons + overflow showing.
You maybe just don't have enough space, you should first remove the title from your Activity by adding this to your onCreate method:
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Then you can see here that the maximum number of icons you can display is directly linked to the width of your screen, on small phones you will only be able to see 2 icons in the ActionBar.

KitKat Transucency just on bottom bar and just on one activity

I'm trying to make just one activity of my app overflowing behind the software keys, like this
What I already did was to put in my theme definition the following statements
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
and then enabled it on the listView I wanted to overlap
android:fitsSystemWindows="true"
android:clipToPadding="false"
What happened was that my app did overlap on status bar and button bar, but this on EVERY activity and not just on the one I put the two rows above.
Also, it messed up my activity margins: the first row of my application drawer is hidden, and the top of my main fragment as well.
I thought fitsSystemWindows was meant to solve this kind of issues, so I added it to my theme
<item name="android:fitsSystemWindows">true</item>
but nothing changed.
So the question is apparently simple: how can I get the translucent bottom bar, with one of my activities flowing behind it, without messing up the top part of my app and without (if possible) having the same effect on all other activities?
Thank you in advance to each of you fellow helpers.
As Eluvatar stated if I need to have this effect on just one activity the best thing to do is to define a custom theme and assign it just to this activity. That's what I did, I defined an empty style in styles.xml and overrided it in values-v19/styles.xml putting just
<!--<item name="android:windowTranslucentStatus">true</item>-->
<item name="android:windowTranslucentNavigation">true</item>
Then I assigned - in AndroidManifest.xml, the proper style to the activity by using
android:theme="#style/Theme.Style.I.Created.For.This.Activity"
Disabling the first row allowed the activity to just overlap the navigation bar without popping out on the status bar. Margins seem ok as well.
I hope this is going to help somebody else someday.

Android Actionbar compatibility alternate xml for pre-honeycomb

I am using the actiobarcompat sample in my application and I am trying to implement search for pre 3.0 devices.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_search"
android:orderInCategory="1"
android:title="#string/menu_search"
android:icon="#drawable/ic_home"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
</menu>
On Honeycomb+ this works fine, the searchview widget appears in the actionbar. What I am trying to do is have a second menu XML so I can fall back to the old search activity way of doing it. However, there is no such thing as menu-v11 folder as the menu folder is essentially menu-v11 because that is the version it started supporting this.
My question is, using the actionbar compatibility sample, is there a way to declaratively add an alternate button for pre-honeycomb?
Can you please be more specific about what you are trying to achieve?
It it's about calling different activities depending on API version, the action bar has nothing to do with that.
You analyse API version in onOptionsItemSelected and act accordingly.
If you want different menu items depending on API version, just create a folder menu-v11 (or menu-v14) and put
version-specific xml-s- there.
BTW, I use com.android.actionbarcompat and it works great for me!

Categories

Resources