I am looking to hide the Sherlock action bar on single tap and show it when user does another single tap thus showing/hiding on alternating single tap.
The code for showing and hiding is:
#Override
public boolean onSingleTapConfirmed(MotionEvent e) {
ActionBar actionBar = getSupportActionBar();
if (actionBar.isShowing()) {
actionBar.hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
} else {
actionBar.show();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
return super.onSingleTapConfirmed(e);
}
The above code works fine for me but the problem is the jerk seen by the user when the transition od action and notification bars occurs from shown to hidden and vice versa.
To avoid the jerk, I added the following line in the onCreate method, but it causes the action bar to cover the UI elements when the action bar comes to visible from invisible state.
requestWindowFeature(com.actionbarsherlock.view.Window.FEATURE_ACTION_BAR_OVERLAY);
Is there any way out by which the jerk is also not there and the action bar is not overlayed on the UI elements when it comes from hidden to visible state?
How about achieving the similar behavior with a sliding menu from top?
you could set roatation to SlidingDrawer and use it
android:rotation="180" // in SlidingDrawer manifest tag.
I understand that SlidingDrawer is deprecated in API 17 but you could always have a custom implementation of this. I'm sure this would be a very smooth implementation for you.
Related
I have Frame Layout(Each Containing RecyclerView), Bottom Navigation Bar and a Custom toolbar.
I want that for each Fragment whenever their is some upward scrolling event occurs, my toolbar should hide and whenever comes back whenever down scrolling event occurs.
Can you help to do this as I am new to Android Programming.
Check This or This.
These questions answer the problem of hiding the bottom bar.
I created an app and I use this example http://developer.android.com/training/implementing-navigation/lateral.html.
when I use the onCreateOptionsMenu(Menu menu) function and menu button create its shown in the first line and the line of the tabs is one behind it. How can I make the tabs and the menu button(three dots)
be in the same line?
I tried this
requestWindowFeature(Window.FEATURE_NO_TITLE);
also this
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
and this is only removed the title and the icon and now I have one empty line with menu button(...)
this its how its look now
Thanks
This is the expected behavior for non-tablet sized screens, so unless you roll your own ActionBar-isque implementation, you can't make the top ActionBar to go away as long as you have menu items.
However if you don't need the menu button, you can remove the top ActionBar entirely through
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
I have added one star icon on Action Bar. Now I want to add click event on that star. If the star is clicked then it should be bright or Turned ON which is OFF by default. And if that star is ON and clicked, then it should go to OFF. I am not getting any idea how to perform onClick event on action bar.
You have a good example here.
Action Bar Example
To add onClickListener to a view in your action bar you have to create a reference to that view first and then in the onCreateOptionsMenu() method you can register the onClickListener.
See the answer to this question here. Its the same principle, you're simply using a 'star icon' instead of a switch.
Even after a long search on this subject I came to no result. So I want to ask here.
In my Android application, I try to set a onClick listener for the menu button in the upper right corner (on the actionbar). When the button is pressed, the NavigationDrawer should open. (I have seen this in an app. Unfortunately, I do not know how this app is called.) I do not want to open the menu.
I have already tried:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:onClick="showdrawer">
<item />
</menu>
with
public void showdrawer(View v) {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.openDrawer(Gravity.LEFT);
}
...but nothing happens when I press the button.
Is there a way to implement this?
I would be very grateful for help.
In my Android application, I try to set a onClick listener for the menu button in the upper right corner (on the actionbar).
First, there is not necessarily a "menu button in the upper right corner (on the actionbar)" on all devices, when using the stock action bar implementation. It will depend upon API level of the device and whether the device has an off-screen MENU key.
Second, that is for the overflow. Please leave it alone.
Third, you have no direct access to that button anyway.
When the button is pressed, the NavigationDrawer should open
The navigation drawer is usually opened by tapping on the left side of the action bar, on the app icon, particularly when it has the "mini-hamburger" on the left edge. That is handled for you via ActionBarDrawerToggle, if you are using DrawerLayout for the navigation drawer.
It is possible to have a right-hand drawer as well, though I seem to recall Google advocating that more for contextual operations. They do not cover this in the written design guidelines, but I seem to recall seeing it on an Android Design in Action video. For that, you might use your own regular action item in the action bar as a trigger, if the right-hand drawer is for activity-level contextual operations.
I have just started developing an Android app and have no experience at all. I have read a lot about Activities / Fragments / Widgets, but don't seem to find a clear answer to my question which is:
Can I create the Action Bar for the app as a fragment so whenever I change an activity I will simply call the one action bar (i.e. the one fragment)? I intend to develop a dynamic UI to create fragments for individual option and thought that it would be easy to have a general Action Bar appearing on all pages.
When you want to customize the ActionBar in all your Activities, the first step is to create a custom Theme in XML.
In this theme, you can customize nearly everything
Please refer to this excellent blog post: http://android-developers.blogspot.be/2011/04/customizing-action-bar.html
Using a Fragment for the ActionBar would be crazy!
If you want to add some code programatically in all your Activities, simply extends a custom Activity, for instance MyCustomActivity, that extends Activity.
public class MyCustomActivityextends Activity{
In this class, you can use getActionBar() and tweak it according to your needs
If you wanna have one ActionBar for all your Activities use inheritance. Create an Activity which simply handles the ActionBar like you wanna have and make it the Superclass like this.
public class ActionBarActivity extends Activity{
public void onCreate(... ) {
ActionBar actionBar = getActionBar();
// + some other method calls of your choice
}
public onCreateOptionsMenu(Menu menu){
// create your actionbaritems here
}
public boolean onOptionsItemSelected(MenuItem item) {
// handle your click events for the items here
}
}
Now you can use this Activity for all your Activities with inheritance:
public class MyActivity extends ActionBarActivity{
...
}
With this setup you are free to use Fragments as you like.
Keep in mind that every time you call a new Activity the callbacks of the super class will be invoked.
I think what you're thinking of is this:
You want your action bar to be the same on every screen, and only need to program it once.
The approach I use, is that the actionbar live in a root activity, containing a single viewpager. And all of the screens that the user interacts with are Fragments in that view pager.
If you create a blank android project in eclipse, and select actiobar with tabs, the project will set this up for you and you can see how that works.
In most cases this would be an unnecessary complication. Once you get started, you will probably find that just a few simple lines of code will create an "identical" Action Bar in each activity .Themes etc can be added later. Better questions at this stage might be should I use Action Bar Sherlock to enable better support of old devices ? and you should think about the overall structure of your app e.g activities / fragment activities / fragments / tabs so that you are able to get something working quickly that can be readilly extended as you develop you full solution.