I would like to change the predefined style of the zoom controls in my application to appear like the new zoom controls in the google maps application. See below:
How can I do it? I have been looking around and I haven't found anything.
Thanks in advance.
You should have four image drawables namely:
Zoom in (+) enable/disable
Zoom out (-) enable/disable
Put them in MapView layout an ImageView or Button with background image as the above drawables.
Then you should assign onClickListeners like:
zoomIn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
mapView.getController.zoomIn()
checkzoom();
}
});
zoomOut.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
mapView.getController.zoomOut()
checkzoom();
}
});
public void checkzoom() {
if(mapView.getZoomLevel()==1) // dont know if 0 or 1, just wrote it
{
zoomOut.setEnabled(false);
// or u can change drawable and disable click
}
if(mapView.getZoomLevel()==18) {
zoomIn.setEnabled(false);
// or u can change drawable and disable click
}
}
EDIT:
I solved the problem this way: disabled built in zoom controls (setBuiltInZoomControls(false)), added my own buttons to UI and added handlers for click on button events.
Related
I'm trying to do something like this:
When I go to this activity I have what is in black and some objects like EditText boxes.
Once I press the button I want those EditBoxes an other stuff that is up there to stay visible but unable to be edited (that's easy to do from code overriding onClick).
But at the same time I also want to load some layout down inside the same activity (from an xml) and change the button function to act over the objects of the new layout.
Could anyone give me an idea on how to do this two things staying in the same activity?
Update:
public void createButton(){
create_button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
editText1.setEnabled(false);
editText2.setEnabled(false);
hidden_layout.setVisibility(View.VISIBLE);
create_button.setText("New text");
}
});
}
On the first click I want the button to do that. But once it's pressed I want it to do another thing. How could I do that?
(that's easy to do from code overriding onClick).
Actually I would recommend enable or disable which is easier to trace by using
view.setEnabled(bool);
as for the other question I'd recommend adding the layout from the start with setting visibility to GONE and when needed set the visibility to VISIBLE
view.setVisibility(View.VISIBLE);
view.setVisibility(View.GONE);
Ok, I've realized it was a dumb question, just add a flag an edit it:
public void createButton(){
create_button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!button_pressed) {
editText1.setEnabled(false);
edittext2.setEnabled(false);
hidden_layout.setVisibility(View.VISIBLE);
create_button.setText("New text");
button_pressed=true;
}
else{
create_button.setText("Second click");
create_button.setEnabled(false);
}
}
});
}
}
I have a simple android webview app and I want to add zoom in button only,
I added the zoom in button in the graphical layout:
but how can I make it work in the java file ?
In your activity, add an on click listener to your button that zooms in the webview:
findViewById(R.id.zoom_in_btn).setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v)
{
webviewer.zoomIn();
}
});
I'm using AchartEngine to draw graphs,
is it possible to disable only the zoom out button ?
thanks.
You can disable the original zoom buttons with below code
mRenderer.setZoomButtonsVisible(false);
and write your own button just to zoom-in inside your xml file and do something like below:
ImageButton btnZoomIn= (ImageButton) findViewById(R.id.btnZoomIn);
btnZoomIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mChartView.zoomIn();
}
});
I want to change the image of a button in my code. I found this can be done in xml:
please check this link
but the image will not stay on after I released the button. I want to click the button
and the button change to a new image. Can this be done?
in onClick method you need to change the Button's image, this way..
public void onClick(View v) {
if(v==buttonName){
buttonName.setBackgroundResource(R.drawable.imageName);
}
}
Assuming an ImageButton...
You can change the background image in an onClick listener, similar to the following:
myButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//set button image
myButton.setImageBitmap(myBitmapFile)
}
});
Is there a way to always show the zoom controls on a MapView? I have added the zoom controls using
map=(MapView)findViewById(R.id.map);
map.setBuiltInZoomControls(true);
but the zoom controls fade in and out. I want them to always be visible.
Solved this by putting my own ZoomControls in my layout xml:
<ZoomControls android:id="#+id/zoomcontrols"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
and then setting up onClickListeners for then to handle the zoom:
zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mapController.zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mapController.zoomOut();
}
});
Intrications' solution does work, but you lose the built in functionality where the button disables when you have zoomed in or out all the way. You can retain this functionality by using the following instead:
localMapView.getZoomButtonsController().setAutoDismissed(false);
However, this does not let you place the controls wherer you want in the panel, and although it does not go away, it does not show up the first time until the user touches the screen once. I tried calling setVisible(true) on the controller, but that does not seem to work for some reason.