achartengine custom zoom buttons - android

Is there an easy way to use custom images for Zoom Buttons?
I'd like to use default setZoomButtonsVisible functions to manage
show/hide buttons.
How can I override those buttons?
I'd like to use icons from my res/drawable (drawable-hdpi, drawable-ldpi ..)
to make sure images will be good looking on all screens.

You can hide original zoom buttons and enable external zoom:
private XYMultipleSeriesRenderer mRenderer; //or any of other renderer
mRenderer.setZoomButtonsVisible(false);
mRenderer.setExternalZoomEnabled(true);
//then add click events tot he imagebuttons on the view
//mChartView --> private GraphicalView mChartView;
ImageButton btnZoomIn= (ImageButton) findViewById(R.id.btnZoomIn);
btnZoomIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mChartView.zoomIn();
}
});
ImageButton btnZoomOut = (ImageButton) findViewById(R.id.btnZoomOut );
btnZoomOut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mChartView.zoomOut();
}
});
Hope it helps.
The only problem is that some strange think is happening on the click. I posted problem here and also as an issue.
Hope somebody will find an answer.
Toni

I'm using almost the same way I think. I've got:
renderer.setZoomEnabled(true);
renderer.setExternalZoomEnabled(true);
renderer.setApplyBackgroundColor(true);
And I'm using .xml file for my buttons layout. I'm not using <ImageButton> in my code. I'm using <Button> with background. And in this way these buttons are images. My code for button:
<Button
android:id="#+id/zoomin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#drawable/action_zoomin"
android:hapticFeedbackEnabled="true"
android:layout_marginRight="15dp">
</Button>

Related

How to bring the Badge Count in front of the Button in android?

I am trying to show the number of notifications on the top right corner of the button and I am using ViewBadger (an external library : android-viewbadger http://jgilfelt.github.io/android-viewbadger) for it. The problem I am facing right now is the badge is showing at the back of the button like this
here is the snapshot
But I want to display the badge in front like facebook or any other app
Here is my code
package com.daimkhan.badgerview;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.readystatesoftware.viewbadger.BadgeView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View button = findViewById(R.id.button);
final BadgeView badge = new BadgeView(this, button);
badge.setText("8");
badge.setTextSize(12);
badge.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
badge.setBadgeMargin(0, 0);
badge.show();
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
badge.hide();
}
});
}
}
please help me in this, thanks in advance :)
try this before showing the badge
ViewCompat.setTranslationZ(badge, 10);
This changes the elevation of the view with respect to Z-axis.
The official documentation says
setTranslationZ
void setTranslationZ (View view, float translationZ)
Sets the depth location of this view relative to its elevation.
it works fine for me, with the same code you provided;
try to use this as your layout file(may be the problem is in your layout):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"/>
</RelativeLayout>
Heads up, the button will auto adjust its translationZ value each time it's clicked, thanks to stateListAnimator (This exists, at least in part, to make sure buttons come to the front when they are clicked... this is not always desirable). For full Z order control over views when one or all of them are buttons, turn off stateListAnimator in xml with android:stateListAnimator="#null"

Changing image dynamically in an ImageButton

XML
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton1"
android:src="#drawable/image1"
android:onClick="buttonClick"
/>
JAVA
--------------------
public void buttonClick(View v)
{
Button aButton = (Button)v;
aButton.setBackgroundResource(R.drawable.image2);
}
Here's what I've tried so far with no luck...
I want to be able to click the button and change the image to image2, there's also going to be other images i'll change it to based off of other variables. I'm just really stuck.. I'll continue looking at other questions and if I find an answer I'll post it here.
Your buttonClick() needs fixing:
public void buttonClick(View v)
{
ImageButton aButton = (ImageButton)v;
aButton.setImageResource(R.drawable.image2);
}
the View is an ImageButton, not a Button. The src attribute is updated via setImageResource, not setBackgroundResource.

how to have a single activity class for many Image Buttons

I have a footer in all the layouts for a android application.
The footer will have Image buttons like "Help", "Home", this Image buttons directly link to Help class and Home class.
Can I have a one single activity class for all the footer Image buttons.
I tried with
public class FooterItems extends Activity implements OnClickListener {
#Override
public void onClick(View view) {
if(view.getId() == R.id.footerBtnHome)
{
Intent myIntent = new Intent(view.getContext(), MainActivity.class);
startActivityForResult(myIntent, 0);
return;
}
if(view.getId() == R.id.footerBtnFeedback)
{
Intent myIntent = new Intent(view.getContext(), Feedback.class);
startActivityForResult(myIntent, 0);
return;
}
}
}
but I am not getting how to call these in a class... for example the project is having MainActivity class in which I have
ImageButton buttonFeedback = (ImageButton) findViewById(R.id.btnFeedback);
buttonFeedback.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Feedback.class);
startActivityForResult(myIntent, 0);
}
});
When I call Feedback.class with onClick from one Image Button... layout and same footer items appears.
I want to use the generalised FooterItems class so I can have one class for footer and use in every other layout.
I am also using android:onClick="onClick" in xml for Image Buttons for footer only.
But how to call those generalised class FooterItems and make it work.
Looking forward to the reply.
thanks.
I can suggest another variant:
I think, you can add to XML android:onClick, for example:
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/self_destruct"
android:onClick="selfDestruct" />
And when user click this button, android programm call method selfDistruct. You just have to implement this method. Android tutorial: http://developer.android.com/reference/android/widget/Button.html
What you are asking is not much clear.
You want to have Help, Home, etc. Image Buttons as common to all layouts in your application correct ?
If you click any Image Button, you have to show the layout on top and these buttons also has to appear on screen??
If yes my answer may help you.
You told i will create footer items as one activity, but its not good. I will prefer ViewFlipper in this case. See the layout.
<LinearLayout vertical>
<ViewFlipper id=vf>
<include layout1 />
<include layout2 />
<include layout3 />
</ViewFlipper>
<LinearLayout horizontal>
<ImageButton button1 />
<ImageButton button2 />
<ImageButton button3 />
</LinearLayout>
</LinearLayout>
Initially you will get layout1 and all image buttons on screen. If you want to show layout2 when you click button3 write onClickListener as below.
ViewFlipper vf = (ViewFlipper)findViewById(R.id.vf);
The variable vf is used to change layouts.
button3.setOnClickListener(new View.OnClickListener() {
public void onClick() {
vf.setDisplayChild(1);
}
});
I hope it may help you. Bye.
I am sure you want to implement Footer view with 2 buttons: Help and Home, this should be at bottom of every activities.
If you want to implement a code for once then follow the below steps:
Define a footer layout with 2 buttons, define android:onClick="btnHelp" for help button and android:onClick="btnHome" for home button.
Now you can include this layout inside any activities by using <include>.
Define a base activity with below 2 methods.
Now extends this base activity wherever you implements this footer layout.
public void btnHelpClick(View v)
{
// do your task for Help
}
public void btnHomeClick(View v)
{
// do your task for Home
}

How do you incorporate TextSwitcher on top of a Button?

I wanted the text on my buttons to switch every time that I click it. The only way I know how to switch text is Textswitcher, but I can't seem to find a way to use it with the buttons. I'm sure this is a simple answer and appreciate any help!
XML file portion...
Button
android:id="#+id/Button_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="#dimen/help_text_size"
android:minWidth="10px"
Java:
Button alphaButton = (Button) findViewById(R.id.Button_A);
alphaButton.setText(mGameSettings.getString(GAME_PREFERENCES_RIGHT, ""));
alphaButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
handleAnswerAndShowNextQuestion("a");
}
});
I'm pretty sure you should just be able to call Button#setText() in the onClick listener

How to Change a Button's Icon Programmatically?

I already have the button:
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:drawableLeft="#drawable/empty"
android:id="#+id/buttonMyText"
android:text=" myText"
android:textSize="20px"
android:gravity="left">
</Button>
I have the "empty" icon show on the button when the program starts.
What I want to do is change the button's icon automatically from my code (low, medium and high) based on user inputs
I tried:
Button myButton = bla... bla... bla...
But I cant figure out
myButton.(what?)
If you check the docs, you'll see the code equivalent for each XML attribute.
See here: http://developer.android.com/reference/android/widget/Button.html
Searching for drawableLeft shows:
android:drawableLeft:
setCompoundDrawablesWithIntrinsicBounds(Drawable,Drawable,Drawable,Drawable)
if you want to change icon at button click event then try this code...
buttonMyText.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
buttonMyText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ImageNameHere, 0, 0, 0);
buttonMyText.setTextColor(Color.BLACK);
}
});

Categories

Resources