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.
Related
Alright, I am trying to understand what I would lose if I use Toolbar as a self-managed ActionBar and not use setSupportActionBar.
AFAIK, all that ActionBar does is, provide placeholders for logo, navigation and menu items and also let Fragments add/customize the menu items.
The same functionality could be achieved using Toolbar.setLogo(), Toolbar.setNavigationIcon(), Toolbar.setNavigationOnClickListener() and Toolbar.inflateMenu() apis. Of course, directing the menu handling logic to Fragments might be lost but I think that is not that big of deal if the Activity knows which Fragment is on top and changes the menu items accordingly.
I am trying to make sure :
If I can achieve every ActionBar capability just by using Toolbar and MenuItems (and not using setSupportActionBar()).
Is it ok to not have an exhaustive knowledge of ActionBar apis. Some of the ActionBar apis are very confusing. Using setHomeAsUp api to show hamburger icon, back icon etc., doesn't feel right. If someone starts learning android today, do they even need to understand the framework's ActionBar apis?
Update : In the article Android Design Support Library under section CoordinatorLayout and the app bar, I learnt that the new paradigm app bar is a replacement for the action bar paradigm. I think action bar will soon be deprecated and we should get used to the new app bar paradigm which covers the new material design user experiences.
Yes you can use achieve similar capabilities of ActionBar in Toolbar.
Mainly the difference lies is Toolbar becomes part of View so we can much more fun playing with them to get Scrolling Techniques
You can use Toolbar separately as View & perform ActionBar alike functionalities. For example, in one of my app I use 2 Toolbar one which is set to setSupportActionBar() while other is just used for some other functionalities.
Conclusion: Well it depends upon your requirements if you want to use Toolbar as self or framework. None the less you can use it as both.
I hope this answers your question well.
To me you are right.
From AppCompatDelegate source code, method setSupportActionBar(),
When set to a non-null value the getSupportActionBar() method will return
an ActionBar object that can be used to control the given toolbar as if it were
a traditional window decor action bar. The toolbar's menu will be populated with the
Activity's options menu and the navigation button will be wired through the standard
android.R.id.home menu select action.
So these are most, if not all, the benefits you will have. As you said, it is easy to implement navigation and menu inflating through Toolbar APIs. However, I don't see what you would gain by not calling setSupportActionBar().
YES YES YES
using setSupportToolBar() is the same old Actionbar the only reason ToolBar is ToolBar is for versatility,same as Fragments is to Views, all lies on how you implement stuff, and also the old Actionbar is kinda boring and much restricted as to Toolbar
I want to have an action bar placed vertically(Tablet App)
Can I have this? I know the default action bar does not support this.
Can sherlock action bar?
Can any other?
I have given this time but I dont see any solution to this.
Can sherlock action bar?
No. It backports what's available in the built-in ActionBar.
Can any other?
AFAIK no library provides such functionality.
Can I have this?
Of course you can. Depending on what you use from ActionBar this could be easy. On The image you have provided there is a FrameLayout with two Buttons and additionally hidden overlay ListView after pressing bottom Button. Not too much work.
How can i archive a Tab layout like this in Android ? The Tab Navigation is part of that
Main ActionBar and is not below. PS: Im using ActionBar Sherlock
At the moment is just do:
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
But i want a look like this:
Thanks for help,
Kitesurfer
I don't recommend doing this but you could override the ActionBar and ABS styles:
<bool name="abs__action_bar_embed_tabs">false</bool> //for ActionBarSherlock
<bool name="action_bar_embed_tabs">false</bool> //for default ActionBar
Tab will be displayed in actions bar but only if action bar has space. When you are in landscape mode your tabs will move to action bar because in landscape mode action bar has more room.
From this thread. On the topic of overriding the Action Bar tab functionality.
Jake Wharton
I am obligated to tell you this is probably a Bad Idea™ and I don't recommend it. When you fight the platform you almost always end up losing.
I am inclined to agree about fighting the platform. Instead I opted to abandon the stock tab navigation (from both the android platform and ABS library) and instead wrote a layout that looks basically the same as the tabs, and used it as a custom view, applying it using ActionBar.setCustomView(View) and ActionBar.setDisplayShowCustomEnabled(true) methods.
This uses the ActionBar api in the standard way (ie. Not fighting the platform) and, as is pointed out in that thread, the tab view is simply a LinearLayout.
Try this. This implements a method that will let you select whether you want the tabs in a separate row or in the top row, regardless of screen orientation.
For those who are using this code with the native ActionBar, simply omit the if (actionBar instanceof ActionBarWrapper) and the block underneath it.
Bear in mind, though, that this is somewhat of a hack and might break in future Android versions.
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.
I have have some problems with devices that have the action bar. When running on a phone I want to go fullscreen with no title bar and no status bar. On tablets I want to show the action bar but still no title bar. Minsdk is 7! The method setTheme doesn't work when you toggle fullscreen so I can't have two themes. Is there a way to show the action bar in fullscreen mode? The support library doesn't support the Action bar.
The only reason I want to do this in the first place is cause they for no good reason at all broke the backward compability by moving the menu key to the action bar. The easy solution for this according to the docs is to add android:showAsAction="ifRoom" to the menu items. But that does absolutly nothing.
I've also tested numerous solutions I found on google that supposedly toggles fullscreen. None of them work on any of my devices so please do not point to something you've read if you haven't used it yourself.
EDIT: I Solved this. The problem seems to be that you have to specify a Holo theme to get the action bar back. Otherwise it won't show. I added this in my main Activity.
#Override
public void setTheme(int resid) {
if(isTablet(this))
{
super.setTheme(android.R.style.Theme_Holo);
return;
}
super.setTheme(resid);
}
On tablets I want to show the action bar but still no title bar
The action bar replaces the title bar. There is no concept of an activity having an action bar and a title bar.
Is there a way to show the action bar in fullscreen mode?
AFAIK, no, by definition.
The support library doesn't support the Action bar.
ActionBarSherlock provides a backport of the action bar for API Level 7 and higher.
The easy solution for this according to the docs is to add android:showAsAction="ifRoom" to the menu items. But that does absolutly nothing.
It certainly "does nothing" if you have no action bar. If you want a fullscreen experience, then you will need to roll your own menu replacement. IMHO, most fullscreen apps did this already (e.g., a game going with a game-styled "menu").