I was viewing a different question Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps) and as you can see he's using the requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); to make the map v2 use the full screen. I tried this but the my location button is partially covered by the action bar on mine unlike his. Does anyone know how to move it down slightly?
Thanks!
Unfortunately you don't have any control over this button. Obviously, you can search for this button id in android sources and change layout params manually from the code, but I definitely wouldn't do that.
This button is super easy to implement yourself. So I recommend to disable built-in "locate me" button and implement your own which will be positioned right below the action bar.
To disable it use:
googleMap.setMyLocationEnabled(false);
New button onClick method content:
googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(googleMap.getMyLocation().getLatitude(),
googleMap.getMyLocation().getLongitude())));
You can just get the view by its id and re-set the top margin Apparently the id is always 2, but this isn't documented and your app will break when/if the id ever changes. Like Pavel said, it's safer to make your own location button and wire it up.
Unfortunately, calling ActionBar.getHeight() in your onCreate will always return 0 since layout hasn't finished. The way to get the real heigh is by using a listener on the ViewTreeObserver:
mainLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
int actionBarHeight = getActionBar().getHeight();
// TODO: set margin of views dependent on actionbar height
// remove the listener
mainLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
}
Related
I want to apply the same ripple drawable properly on multiple buttons. But it's not happening because, the ripple effect is only getting applied on the last button. I have also used gradient drawable inside the ripple drawable. That works fine on every button. It just the ripple effect is not getting applied on any button except the last button. It is also not working on api level 8. I know that this method doesn't work on apis before api level 21. But I haven't found any tutorial on dynamic button design.
I'm doing everything inside the on-create event. I can't write the codes outside of the on-create event and also can't use any XML for this particular situation I'm in.
Here's the output:
Here's the code:
android.graphics.drawable.GradientDrawable gd_btone = new android.graphics.drawable.GradientDrawable();
gd_btone.setCornerRadius(4);
gd_btone.setStroke(2, Color.parseColor("#ffffff"));
gd_btone.setColor(Color.parseColor("#232323"));
android.graphics.drawable.RippleDrawable ripdr = new android.graphics.drawable.RippleDrawable(new android.content.res.ColorStateList(new int[][]{new int[]{}}, new int[]{ Color.parseColor("#888888")}), gd_btone, null);
button1.setBackground(ripdr);
button2.setBackground(ripdr);
button3.setBackground(ripdr);
button4.setBackground(ripdr);
Also, can anyone help me to make this piece of code back-compatible with api level 8 and how to set margin on this drawable?
I'm not a Android developer so I don't know much about it.
What I see is that the dripple effect is applied to the last button, even when the other buttons are clicked. Because of this, I am thinking that the RippleDrawable class does not support the kind of behavior you are looking for; a single instance can only be bound to one button at a time.
I would suggest simply creating four separate RippleDrawable instances.
Disclaimer: I have not worked with RippleDrawables, but this is purely based on the output you've provided and personal experience with Android development.
i would like to ask a question with regards to AlertDialogs which i would like to use in GoogleMaps V2. I read about the custom InfoWindow documentation from the android developers and noticed that they advised not to put any interaction widgets (Buttons, Textbox etc etc) onto an OnClick function. Now, i would like to know if i could use a default alert dialog and put it into an OnClick function for the custom InfoWindow. Is it possible?
Yes that should work fine. The reason why you should not (and cannot, really) put interactive elements in an InfoWindow is because the InfoWinow is statically rendered when shown, making any interactive elements you place in it effectively useless.
After a while of googling I cannot find what I need, I see some libraries which look to do it but I have already implemented the system using androids default methods.
I set the markers like so:
theMap.addMarker(new MarkerOptions()
.position(new LatLng(lat, lon))
.title(title)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_map32))
.snippet(strap));
However I need a 'detail disclosure button' like on iOS (transitioning app from iOS to Android) and I can't seem to add a button to the marker - is it possible using androids system?
This cannot be done.
from the docs
Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.
in other words you cannot put a button in the infowindow and be able to use it. You will need to use a dialog of sorts if you want to do something like that
There is always some way.
A nice hack can be found here: https://stackoverflow.com/a/15040761/2183804
I haven't tested it myself, but from the comments there (and the amount of upvotes) we can deduce it works well.
You can track clicks only on Marker. If you want a button on marker - click on marker & show a dialog with buttons.
I know this may not be an appropriate question, but I want to know how a touch enabled OS like
android detects a button in an app and calls the appropriate handler? When programming an app we just give the alignment information of a particular button. So, how android keeps the mapping between a button and screen position? I think this is kindof dynamic because if you change the screen orientation or use zoom or something like that the button positions are changed dynamically. So, android must look at the touch position and decide whether a button is there or not and call the appropriate handler. How this all things put together?
I appreciate any reply.
I'm currently implementing theme support for my application and a part of it is changing the action bar app icon. I want to use a dark icon when Holo Light is selected. Everything is done in the method except for the part where the action bar app icon is set. The code that I'm trying to use is:
getActionBar();
ActionBar.setIcon(R.drawable.my_icon);
"There is no such reference available here" is the error that I'm getting. How should this be done correctly?
BTW my minSdkVersion is 14 so no action bar Sherlock stuff.
getActionBar();
You're throwing the action bar away right there. getActionBar() returns an instance of ActionBar, which you then need to call setIcon() on. Like so:
ActionBar actionBar = getActionBar();
actionBar.setIcon(R.drawable.my_icon);
Though its a bit late answer but i thought it might be useful.
From inside an activity:
For API level 14 or higher:
getActionBar().setIcon(R.drawable.my_icon);
For lower API level we have to extend ActionBarActivity and then:
getSupportActionBar().setIcon(R.drawable.my_icon);
From inside a Fragment:
For API level 14 or higher:
getActivity().getActionBar().setIcon(R.drawable.my_icon);
For lower API level we can use (activity must extend ActionBarActivity):
((ActionBarActivity)getActivity()).getSupportActionBar().setIcon(R.drawable.my_icon);
And in both cases we have to call setDisplayShowHomeEnabled(true) before setting the icon or logo.
((ActionBarActivity)getActivity()).getSupportActionBar().setDisplayShowHomeEnabled(true);
((ActionBarActivity)getActivity()).getSupportActionBar().setIcon(R.drawable.my_icon);
I am using this for my use , and it's working for me. Hope this help all
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.icon);
You need to add the drawable that you want to reference into your drawable/ folder under res/.
edit: In your Android installation folder there are a lot of stock images to use. You can probably find it there.
The existing answer is very correct. There is, however, also an alternative.
A minimal approach would be to use
getActionBar().setIcon(R.drawable.my_icon);
Gets your job done right away. :)
Technical Details: Since getActionBar() by default returns an object, you can directly manipulate it without having to receive it in an in-scope object explicitly.
Calling to setIcon wasn't enough for me.
Before that, I had to switch the display from activity logo to activity icon:
actionBar.setDisplayUseLogoEnabled(false);
For the differences between activity icon and logo see Android icon vs logo.
Try this
setSupportActionBar(toolbar);
if (getSupportActionBar() != null)
getSupportActionBar().setIcon(R.drawable.your_icon);
Kotlin answer:
In your activity just paste this code.
You need to enable the option first:
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.setIcon(R.drawable.your_icon)