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.
Related
I'm writing a library that starts a flow of activities when the user does some action. If back is never pressed, the flow should be:
Application using library detects some action on ParentAppScreen1 >
LibraryActivity1: user taps next >
LibraryActivity2: user taps send >
user is returned to ParentAppScreen1
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
this.finish();
return true;
case R.id.action_send:
sendReport();
// TODO go back to where the user started in parent app
}
return super.onOptionsItemSelected(item);
}
Is there any kind of standard practice for this? I'm not finding much when browsing documentation, and I'm not really sure where to start.
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);
I added an option menu in my app.
I want activity's whole background appear dark when menu key is touched so the user can see option menu well.(like when a dialog is displayed)
Should I use animation to do this or is there any other way?
As you're using OptionMenu, you could do:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.your_option_menu:
mRootLayout.setAlpha(0.5f);
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
mRootLayout would be the root layout from the xml you set the view in your activity. Just use findViewById to set it.
After you select a final option in your menu, make sure to return the alpha property of the root layout to 1.
I would like to have an ActionBar in Android similar to evernote where in the top right there is a sign that if touched triggers an action. How do I put this in writing clickable? And as I move to the right?
You need to override OnOptionsItemSelected() method in your activity. You can also check the for offical doc for full tutorial
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menuItem1:
action1();
case R.id.menuItem2:
action2();
default:
return super.onOptionsItemSelected(item);
}
Good luck
What is the correct way to change background color of a MenuItem? I would like to change it to sinalize that MenuItem is active but i didn't find how to do it.
By now, i'm changing icon for another one with different color but i don't need it, i just need to put some color on background when it is clicked.
Here is what i'm doing to change icon:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.mnNow:
item.setIcon(getResources().getDrawable(R.drawable.now_icon_active);
this.displayFragment(getNowFragment());
break;
default:
super.onOptionsItemSelected(item);
break;
}
return false;
}
How can i change background color when it's clicked and keep the color until the user choose a new option?
Thank in advance.