I wanted to replace the deprecated version of android.support.v4.app.ActionBarDrawerToggle so i looked a little and found how to do it : How to implement DrawerArrowToggle from Android appcompat v7 21 library
Except it doesnt work : I get this error This Activity already has an action bar supplied by the window decor
And if I change the style the action bar wont be seen.
Related
I am building an Android app and want to have a button always visible on the actionBar. I followed this guide and others, but none of them seem to solve my problem (although they are very close I guess...).
I have the package "app" and use app:showAsAction="always". No error is shown, but no button on the bar as well. When I change it to android:showAsAction="always" the button appears on the bar, but AndroidStudio tells me I should go for "app:showAsAction with appCompat...".
I have a custom theme with parent="#android:style/Theme.Holo.Light.DarkActionBar"> and for the bar itself: parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">.
Should I change something and get app:showAsAction working, or ignore AndroidStudio error message and go for android:showAsAction?
This is the documentation of the lint rule:
AppCompatResource
Summary: Menu namespace
Priority: 5 / 10
Severity: Error
Category: Usability
When using the appcompat library, menu resources should refer to the
showAsAction in the app: namespace, not the android: namespace.
Similarly, when not using the appcompat library, you should be using the
android:showAsAction attribute.
I think the problem is that you are mixing Framework Activity and AppCompat menu.
You should use AppCompatActivity with AppCompat Action bar and app:showAsAction; or Activity with android:showAsAction.
Recently I switched to the v7 Support Library to integrate Material Design elements.
Since then, my contextual action mode is displayed on top of my action bar instead of replacing it (like in another activity of my app).
actionMode on top of actionBar
actionMode overlaying actionBar
I can't figure out why this is happening, because the code for starting and preparing the ActionMode are nearly the same in both activities. I always start them with startActionMode(actionModeCallback); and then inflate the menu.
If you need code samples, feel free to ask. Any help would be appreciated.
Solved it myself: I didn't use the ActionMode version from the support library.
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.
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();
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.