Action bar with written clickable? - android

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

Related

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.

I am trying to setup "action bar's Up/Home button" on my other activities but I keep getting an error "NavUtils". How can I solve this?

// this is code on my other activities
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
//NavUtil show error
//suggests creating another class
return true;
}
return super.onOptionsItemSelected(item);
}
}
Make sure you have latest Android.support.v4.jar added to your lib files.
Also there are a few known issues with this files. See the link below:
Download Android Support v4 Jar Revision 9 (!)

Drag & Drop ListView Item on long press of it in Android

I'm using this library to implement Drag & Drop feature for my listview items. This works greatly but needs a handler(i.e an imageview or any other view to press) to drag the items. I need to implement drag & drop for long press of listview item. How can I do this? Please help me. Thanks in advance.
You can use method for long clic
public boolean onLongClick(View v)
and if you want keep normal clic add:
public boolean onOptionsItemSelected (MenuItem item) {
switch (item.getItemId()) {
case 0:
//........
case 1:
//..........
case 2:
}
return super.onOptionsItemSelected(item);
}
Try it and tell us.

SherlockActionBar up button won't work on API 10

I'm playing around with the sherlockactionbar library, there is a problem which is the up button won't work on API 10. The up icon can be shown on the actionbar, but it won't respond to my pressing. On higher API such as 16, it functions as expected without problems.
I tried several solutions I came across, but none of them work. Below is one of them.
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpTo(this, new Intent(this, test.class));
return true;
Make sure you have these set:
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
And that your switch is in this method:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case android.R.id.home:
/* Do Something //*/
return true;
default:
return false;
}
}

Categories

Resources