I'm using a ViewPager to scroll between different fragments. There are two types of fragments, using two different menu resources. I'm invalidating the menu to switch between those resources when necessary. That's all working pretty well, but the menu is "redrawn" without an animation.
To prevent having to mess with individual MenuItems I was hoping I could briefly hide the ActionBar while the new menu is loaded, showing it when that's done. That's working as expected as well, but the activity is resized when the ActionBar is toggled.
Is there any way to prevent this from happening, or otherwise hide the ugly transition between menu resources?
I didn't quite catch the menu part of your problem, but there is an easy solution to preventing your activity from resizing when the ActionBar appears or disappears.
You can tell the ActionBar to draw itself in overlay mode, meaning it will float on top of the activity, in stead of actually being part of the activity's layout. Use either android:windowActionBarOverlay in your theme, or the Window.FEATURE_ACTION_BAR_OVERLAY flag from code.
You probably want to use this feature in conjunction with the actionBarSize constant, that specifies the correct offset for the first view in your layout. This way, your content still appears below the ActionBar, but since the ActionBar itself is an overlay, upon hiding/showing it, the activity will not resize.
<SomeView
...
android:layout_marginTop="?android:attr/actionBarSize" />
More details can be found in the documentation.
Related
I try to make an app using one activity multiple fragments pattern. I handle navigation with Navigation architecture component using a bottom navigation view. In one of the fragment I have a Recyclerview which displays a list of custom cards. On item click it navigates to another fragment where I need to hide the bottom navigation view.
The problem appears when I navigate back and set the bottom navigation view visible again. The bar seems to appear in two steps giving the feeling of lag. (first time appears just 60% of the bottom navigation view).
The behavior seems to be related with the status bar. When I change the theme to full screen or I set windowTranslucentStatus=true, everything behaves okay. In addition, first time the nav bar seems to be with exactly 24dp smaller, that is the dimension of status bar.
Have you any idea what can I do?
PS. I'm new on stackoverflow and this is my first question. I'm glad to join this wonderful community.
Delay is one way to go, but I wouldn't suggest that.
I am assuming that the your navigation view is rendered before the entire activity is rendered, which is causing it to be rendered again after the UI is rendered. Why don't you try setting the visibility after the UI is rendered, like here
Just getting opinions here. My app has a toolbar below that are tabs. In the toolbar, there is a SAVE button where I want it to be visible ONLY when certain tabs are in "focus". I accomplished this by setting the menu item to static in the main activity and setting it to visible when the fragment is in "focus". Any downside to doing it like that? Will this cause large overheads?
I've read this question and watch the video clip from Bitspin, however I'm still unable to figure out the techtique they used on ActionBar.
You can observe the ActionBar layout transition inside Timely, when navigating from the settings Fragment to the about Fragment (and navigating back), the up caret and the title is animated by zooming and fading. So how is this made possible?
Or can you let me know if there is some techtique on crossfading ActionBar layout changes? My main purpose is to smooth the transition when user opens the navigational drawer and the title changes, aciton buttons disappears.
Thanks in advance.
EDIT:
I turned on the dev options for showing layout borders and found that Timely is using custom layouts to achieve this. However this is not possible for other applications heavily relying on other ActionBar features such as ActionMenu.
So are there any alternative ways to achieve layout transitions on ActionBar and its ActionMenus?
So I'm working on adding ActionBarSherlock and the Navigation Drawer to a project that previously implemented a custom (very poorly written) "action bar". Instead of using fragments and a backstack of activities for navigation, some activities show and hide different layouts. (That is, suppose I am in a list mode and then select a button to go into an edit screen. The app currently hides the list layout and shows another layout.).
So I've added actionbar sherlock and a navigation drawer to all the activities. I want to be able to programmatically switch the navigation icon from the 3 lines to the arrow when certain buttons are pressed.
I can't figure out how to do this though. Any ideas?
Thanks!
The solution to this problem is to use the method:
setDrawerIndicatorEnabled(boolean enable)
inside the ActionBarDrawerToggle class.
After:
drawer.setDrawerListener(toggle);
Use this code:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.select);
It depends how wedded you are to built-in actionbar artifacts. You can always redraw the current actionbar by inflating a layout of your choosing, then calling
getSherlockActivity().getSupportActionBar().setDisplayShowTitleEnabled(false);
getSherlockActivity().getSupportActionBar().setDisplayShowHomeEnabled(false);
getSherlockActivity().getSupportActionBar().setDisplayShowCustomEnabled(true);
// Inflate and do whatever you need to your view...
getSherlockActivity().getSupportActionBar().setCustomView(abView);
getSherlockActivity().getSupportActionBar().show();
When you want to go back to your standard (assuming you're using a DrawerLayout to do your navigation drawer), you can just set make a call to setDisplayShowCustomEnabled(false) (re-enable showHome and showTitle as you please).
As far as I know, customization of the back button can only be done via themes. Besides, swapping the drawer icon for the back icon (within the same Activity) doesn't make sense, since users would still be able to access the navigation drawer by sliding the left most edge to the right. It just wouldn't make sense.
If you absolutely need the back icon, then it would make the most sense to make that screen a new Activity since you would indeed be adding another "level" to the stack, which is what the back icon represents.
In the Honeycomb ActionBar, I am trying to determine the position of the icons that appear as my ActionBar's 'showAsAction' options. Several of my icons are set to appear only if there is room. I want to include helpful comments under each icon when the application is first run. To properly position the comments , I need an idea of where these icons are.
I have called getActionBar() from the activity and the icons don't appear in the ActonBar's View. I know I can get a handle on the Menu Item through the onPrepare and the onCreate for the OptionsMenu, but they don't contain any positioning information since the ActionBar has not been rendered. Any ideas? I have also explored the onMenuVisibilityListener, but the ActionBar at that point still does not contain any information that I can use to calculate the relative positions of the option menu icons.
If there is a way to also just determine which actionbar items are actually appearing, I can calculate where to place things too.
I want to include helpful comments under each icon when the application is first run.
Then load a different menu XML resource on the first run, one that has withText along with ifRoom for android:showAsAction.
You could make this a configuration option for the user, so the user gets to choose which style to use.
If there is a way to also just determine which actionbar items are actually appearing, I can calculate where to place things too.
Except that you can't actually place anything there. The toolbar buttons take up the full action bar height.