I have a NavigationDrawer having a list with many radio buttons.I want the user to have to select a list item before he can close the Drawer.
The drawer should not close till the item is selected.
Is there a clean way with which I can achieve this??
Set up the DrawerLayout lock mode setDrawerLockMode as follow:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
but you need to handle actionbar home up button.
I would recommend not restricting drawer operations, and just set a default selection, in case the user doesn't select an option.
However, if you insist on doing it, this method seems to be the one to go with:
// Belonging to DrawerLayout
public void setDrawerLockMode (int lockMode, View drawerView)
In onCreate() open it and lock it, then unlock it upon the selection of any of the options. There is no need to recheck during the usage, as radio implies there is always a selection, unlike check box selection.
That would be my first attempt at this, let me know, cheers.
Reference
Related
I am trying to close my navigation drawer after I finish certain activities immediately, without the sliding animation. I don't close it on activity start because I would like it to stay open if the user backs out of the activity. However, I cannot get it to close without a brief flickering animation as it closes itself. I have tried variations of the following code:
protected void closeDrawerImmediate() {
mDrawerLayout.setVisibility(View.GONE);
mDrawerLayout.closeDrawers();
mDrawerLayout.setX(0);
mDrawerLayout.setVisibility(View.VISIBLE);
}
You can use the new DrawerLayout.closeDrawer(int/View, bool) methods in v24 of the support library to instantly close a drawer:
drawerLayout.closeDrawer(Gravity.LEFT, false);
If you just want to close a drawer immediately, such as when you're launching an activity from tapping on a drawer item, that is probably enough.
If you want to close the drawer on coming back to the activity, I'd set a stateful boolean like closeDrawerOnResume = true wherever is appropriate (eg. starting a new activity), and then in onResume check this boolean and close the drawer without animating if it is true.
You can consider setting animation time to 0. But it seems it's not as easy as setting one property. Here is tutorial and the code but it requires importing sources for DrawerLayout and ViewDragHelper into project and small modifications there.
I have a problem.
I have an action bar. It has a drop down list and it has an overflow button and another button some where in between.
Because I use a drop down, I am setting the action bar to use this mode:
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
mActionBar.setListNavigationCallbacks(mActionBarNavigationAdapter, mOnNavigationListener);
mActionBar.setDisplayShowTitleEnabled(false);
My mOnNavifationListener is set to call a REST api depending on which item I chose in the drop down list.
This works as excepted.
The problem is, if I click on the overflow button to reveal extra options (such as settings or more importantly, Signout), I still get the navigation listener activated.
So I thought. Ok let's try to distinguish between the buttons using their position or id which are passed as parameters in onNavigationItemSelected method.
So I added an if statement that checks the position parameter. But...
It seems that the position of the overflow button is ALSO 0 (exactly like the position of the first item in the drop down list, so it passes the check and calls the REST api which is not good.
Also, the third button (not the drop down list or the overflow), has a position of 1 which effectively calls the other REST api...
I can't find a way to distinguish between the items in the action bar.
Any suggestions?
First, I'd strongly consider replacing your use of list navigation, as that is officially deprecated in the "L" Developer Preview and should remain deprecated in the next shipping version of Android.
I still get the navigation listener activated
I am not clear on what you mean by this. I also don't know which action bar you are referring to:
native API Level 11+?
appcompat_v7?
ActionBarSherlock?
Ideally, onNavigationItemSelected() will be called when your activity first appears, then if the user chooses something from the Spinner. If you are saying that it is being called at other points in time, while unfortunate, this can be worked around by simply keeping track, in your own data member, of where you are in the Spinner, and only doing work if the Spinner position actually has changed. So, for example, if you start off showing position 0, and the user taps something which causes onNavigationItemSelected() to be called again with position 0, you know that nothing needs changing, because you are still on position 0.
Recently I implemented the sliding menu library. It is working fine but the problem is by default, the secondary menu(the layout on right),if not open, slides in when its clicked.
What I want is that the click event should be passed on to its children so that the views inside the secondary menu can get click. The user can use swipe gesture to open the secondary menu.
All the answers I've looked at, are meant to disable swipe gesture on the secondary menu and not the click. So, it will be helpful if someone can provide some suggestions :)
You need to update the library to update the default behavior of Sliding menu.
You would have to go into CustomViewAbove class and change the onInterceptTouchEvent method.
Remove mQuickReturn = true; in MotionEvent.ACTION_DOWN:
I'm using the Navigation Drawer Example downloadable here.
I'd like to extend this example to disable the selection of one of the planets. For simplicity, lets say I want to permanently disable the selection of Saturn, and change the text of Saturn to dark gray, and have it not highlight when a user selects it. (in reality, I would like to disable navigation programmatically when a user has changed certain values on the screen not yet saved to the device).
The closest thing I've gotten to this is to stop the selectItem() method from being called from within the onItemClick click listener, but an issue remains even if I do this - the text of "Saturn" still appears selectable and highlights when a user clicks it.
What portion of the widgets do I need to change to prevent the text of Saturn from being highlighted?
I've tried changing
mDrawerLayout.setClickable(false);
mDrawerList.setClickable(false);
But neither of these options appear to have any affect.
Any suggestions or ideas as to how to approach this problem?
A couple helpful notes:
I'm aware that alternatively I can Set the Drawer Lock Mode to prevent the navigation drawer from being opened, but this is much less intuitive than having grayed out nav actions
Is the more appropriate thing to do here to remove the items from the list that cannot be accessed at this time? Similar to as described in the Remove ListView implementation here? The biggest disadvantage to this is that I would probably have to change the listview to describe why items have been removed from this list temporarily.
I'd like to extend this example to disable the selection of one of the planets
Create your own subclass of ArrayAdapter where you override areAllItemsEnabled() to return false and isEnabled() to return true or false as needed.
I have an app that in a certain Activity (drawing) can be in any one of a number of states, such as draw, erase, select, etc.
To enable these states, I've got a button for each in the ActionBar, but one thing I'd like to do is to 'show' the user which state is enabled by keeping the button pressed active or pressed until I turn it off (when they have switched state by pressing one of the other buttons).
Searches here and other places have me coming up blank... can anyone recommend a possible solution? I've though about rolling my own toolbar, and while this might be my final solution, using the ActionBar would speed things up greatly at this point.
Thanks.
There is no direct way to do that, as far as I know, but you could implement your custom component to do that. However, my advice to you is having a separate toolbar that's not on the action bar, since the users expect all buttons on the Action Bar to be "Action Items" which perform something immediate, so having toggle items on the Action Bar might break this expectation. This allows you to save space on the action bar for things that the user expects to see there like: navigation, "Undo", "Save", "Delete"...
I agree with Bruno about the fact its probably best if you do it in a separate toolbar for the sake of user experience standard and your code will probably look better because you cant fully customize the action bar but if you do decide to go with it i can think of something really simple like, when clicking one of the menu buttons you set the pressed button to a new drawable (pressed button) and the others to their normal drawable (not pressed) so each menu icon will have a pressed and not pressed icon. you will have to invalidateOptionsMenu though.
I had the same problem and did not find a solution. However, I found a workaround that works for me:
In the onOptionsItemSelected(MenuItem item) method, if item is the button you want to toggle, simply call item.setIcon() and point to another drawable. I use the same image but with another color to show the user that the button is in "pressed" state. And when the button is pressed again, revert to the original drawable.