Gesture Up (swipe up) from the Navigation Bar android - android

How to handle up gesture from the android navigation bar?
It is essential that item appears when the gesture is made (with pressed at this time the finger on the screen).

#Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
if(item.getItemId() == android.R.id.accessibilityActionScrollUp){ // MANAGE THE UP BAR (return to mainActivity)
NavUtils.navigateUpFromSameTask(this);
}

Related

Drawerlayout with disabled drawerindicator shows only not working arrow

I'm using the navdrawer layout from android to show a filter on the right side of my screen in a sliding menu.
Now I wanted to remove the left icon in the toolbar. I did this as follows:
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerToggle.syncState();
The only problem I'm now facing is that the icon is an arrow and it doesn't do anything and I want it still to have the up behaviour.
I tried something like this:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_filter:
Timber.d("Open or close filter");
mNavigationDrawerFragment.openDrawer();
return true;
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
But this doens't work because onOptionsItemSelected is not called for that arrow?
Anyone an idea?
try :
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

How do you handle the Back button in action bar? [duplicate]

This question already has answers here:
"Back" button on Action bar - Android . How to go "back"?
(2 answers)
Closed 7 years ago.
I tried with this but nothing happens.
#Override
public void onBackPressed() {
super.onBackPressed();
Log.d("TEST", "Pressed the Back button.");
}
Back button oin action bar is Menu item with id android.R.id.home. Here is how you can handle click on up item:
#Override
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case android.R.id.home:
// do something useful
return true;
}
return super.onOptionsItemSelected(item);
}
OnBackPressed Doesn´t refer to that button but to the button on the bottom of your screen (the one next to home)
what you are looking for is to customize behavoiour on the home button
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
//TODO log here
return true;
}
return super.onOptionsItemSelected(item);
}`

Creating Separate OnClick Listeners for Left and Right Navigation Drawers

I currently have two navigation drawers/menus:
However I need a little bit of help setting up an OnClick listener for the right Action Bar menu.
Currently - I have an onclick listener for the left Action Bar Menu
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
However I'm not sure how I might be able to handle an onClick event for the right Action Bar menu.
Any suggestions are greatly appreciated.
Full XML and Java Source:
http://pastebin.com/ygyyjtLZ
Try this:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
} else {
switch (item.getItemId()) {
case R.id.action_more: // change the action_more with your own id in main.xml menu
// do your stuff here (your right click method)
return true;
// rest of your menu actions here...
}
}
return super.onOptionsItemSelected(item);
}

Make app icon clickable without back icon

Can i make my Action Bar app icon clickable without displaying the back icon?
This is my code, it works, I have only layout problem:
actionBar.setDisplayHomeAsUpEnabled(true);
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
//Do stuff
return true;
default:
return super.onOptionsItemSelected(item);
}
}
This is my activity layout, what I want is remove back icon, is it possible?
Try to use setHomeButtonEnabled(boolean enabled) instead of setDisplayHomeAsUpEnabled(boolean enabled). The latter do exactly the same thing as former which is enabling home button but additionally put up affordance sign which you want to get rid off.

How to get Up Event in SearchView android

I need to implement some action after clicking the up icon after searching in my ListView via SearchView. How can i get UP event, i.e. how can i implement the click event for UP icon.
Found my own answer, Instead of relying on UP icon event, i implemented OnActionExpandListener which worked exactly what i wanted.
menuItem.setOnActionExpandListener(new OnActionExpandListener()
{
#Override
public boolean onMenuItemActionCollapse(MenuItem item)
{
// Do something when collapsed
return true; // Return true to collapse action view
}
#Override
public boolean onMenuItemActionExpand(MenuItem item)
{
// Do something when Expanded
return true;
}
});

Categories

Resources