How to click on custom ActionbarSherlock views with Robotium - android

I am writing test cases for my app using Robotium. The app uses ActionbarSherlock for porting the Actionbar on versions prior to 4.0. However the ActionBar items always seem elusive to get hold of. I tried to use this project - https://github.com/atermenji/robotium-actionbarsherlock but didn't have much luck with custom actionbars. I tried the following code:
solo.clickOnVisibleActionbarItem(com.vtcreator.android360.R.id.notification_icon);
R.id.notification_icon is a button defined in the custom action bar layout.
Anyone with experience of both Robotium and ABS?

Since you have source code access anyway, you can choose to access the ActionBar item on a view level.
View actionbarItem1 = solo.getView(R.id.notification_icon);
solo.clickOnView(actionbarItem1);

In my current project which makes use of Action Bar to place Back Key and three action menu items as Image Buttons, following code worked fine -
// Selecting Back function button on Action Bar
// com.main.myapp is the package name of the main application which is under test.
ActionBarView actionBar = (ActionBarView)solo.getView(com.main.myapp.R.id.abs__action_bar);
ImageView backUpKey = (ImageView)actionBar.findViewById(com.main.myapp.R.id.abs__home);
solo.clickOnView(backUpKey);
// Click on Tools Icon on Action Bar Menu
solo.clickOnImageButton(2);

This is the better way to handle :
This Should work along with lib robotium-actionbarsherlock # https://github.com/atermenji/robotium-actionbarsherlock
if (Build.VERSION.SDK_INT < 11)
solo.clickOnActionBarHomeButtonCompat();
else
solo.clickOnActionBarHomeButton();

Related

3 dot/settings in top bar buttons

When in some apps, there are those 3 dots in the top right of the app, on the action bar (not the home buttons), which allow for more options. In my app I have on, but I do not know how to make it do a method when it is clicked. Do I use android:onClick="METHOD_NAME ? Or do I need to setup a button variable in my activity class and setup and onClickListener? I have already tried both but I may be doing something wrong.
That three dots are the menu in the action bar. They are always shown on devices without a menu key.
See also the documentation for more details.
Three dots are called Overflow(very aptly named) and to use them you need to use ActionBar which is the top long, horizontal bar showing icons, other buttons along with the Overflow button.
Now in some devices where there is no physical menu button you will always see Overflow button.
Go through Docs and tutorials related to ActionBar but keep one thing in mind that ActionBar is only available for devices with android above HoneyComb. For android devices below 3.0 such as GingerBread or Froyo you will have to use compatibility libraries, so that will be an additional task.
And most notable libraries for this purpose are ActionBarSherlock and AppCompat.

Moving options menu to another view

I am trying to display the options menu in another place but the ActionBar, is it is hidden.
I have no clue on how to do it nor I find any function to do such things.
I am using Theme.Light.NoTitleBar as theme/style, but still I'd like to have the menu somewhere else, be it a View or a Layout.
Does anyone have any clue?
You would need to use Android support library , which would enable you to use Action Bar in Android Version 11.0 and above. You would also require to use Theme.Holo.Light.DarkActionBar as your application theme to make action bar visible.
After you do this , you may create menu xml file ad inflate it in onCreateOptionsMenu() function , and you can then access Action Bar like this : getActionBar() in your activity.

Android ActionBar Sherlock Swipe Gesture Recogniser

I have an application that has action bar sherlock and SlidingMenu integrated in it, the application has only 3 pages, and they're static pages, so no big deal about them. I have one activity and 3 fragments that i am changing when using the sliding menu.
What i want to achieve is something like this image
I want the user to be able to swipe with his finger on the ActionBar, and when that happens i change the fragment that is being displayed.
Note: i got the gesture recogniser from this awesome answer, but i can't seem to find a way to attach it to the ActionBar.
If i could put a View on the action bar and detect swipe on it, that would be great, but how can i do that ?!?
One last thing, how to implement this "Page Control" in android ?!?
So the answer to my question is that i simply created a custom_actionbar.xml, and then i used this to do the following:
View custom = LayoutInflater.from(this).inflate(R.layout.actionbar_custom, null);
getActionBar().setCustomView(custom);
// and you can use the things in the custom action bar like following !!
Button btnLeft = (Button) custom.findViewById(R.id.btnMenu);
Hope it helps someone :)

ActionBarSherlock wrong tabs position on android 2.2.2

I'm having serious problems getting tabs in actionbarsherlock below main action bar tabs to work in an app that runs from Android 2.2 up and looks like Android 4. (see link)
Tabs position
Have you tried running the official Demos app of ActionBar Sherlock? (https://github.com/downloads/JakeWharton/ActionBarSherlock/ActionBarSherlock-Sample-Demos-4.2.0.apk) It should contain a demo for the actionbar with Tabs.
If that works on Android 2.2 then you know the problem is in your code and you can check the Demos source code to see what you are doing differently (https://github.com/JakeWharton/ActionBarSherlock/tree/master/samples).
It's usual behavior of action bar (actionbarsherlock just simulate it). Use
ActionBar act = getSupportActionBar();
act.setStackedBackgroundDrawable(getResources().getDrawable(R.drawable.mytab_base_t));
to avoid white color in top bar (this option you can't access from any theme item yet). You can also monitor action bar height to change custom view of tabs on-fly, but you can't change action bar behavior, forget it. Otherwise please use PagerTitleStrip against action bar tabs.

Creating Android Facebook-like menu on bottom bar

I'm using Galaxy tab and it's got a bar on bottom that appears all the time.
FB app shows a new item there that used as a menu button.
How can I declare my menu to be there like FB?
Thanks!
I guess they are still using the old options menu. You can achieve that effect by setting the target sdk to max 10. I wouldn't recommend that as the menu button hides information and is not the current way to go (I'd use an ActionBar)
You should definately look at the ActionBar. In addition to the tab navigation that is available, you have an option for a split action bar for top and bottom. ActionBar is part of Honeycomb (3.x), but if you want to support older versions, there is the ActionBarSherlock library.

Categories

Resources