i want to toggle the map view on my android map app - I have been told to use this code:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.mapview :
EVENT HERE TO TOGGLE MAP VIEW TO AND FROM SATELLITE
default :
return super.onOptionsItemSelected(item);
}
}
However, I added this code to the end of my map page code -- but i don't know what to put in the middle to make this menu item actually toggle from the different maps available. Help???
If I get you right, you should do something like that:
case R.id.mapview :
myMapView.setSatellite(!myMapView.isSatellite());
break;
Related
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.
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 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
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.