1

So I got following problem: I'm currently developing a sensor app and I'd like to check if the sensors are available or not. If they aren't, I want to change the color of a button (which starts an activity where the value of the sensor is being displayed) to grey. Sadly, I can't just change the background color of the button because I'm using the Circle Button Library by Markushi. This button looks like this:

<at.markushi.ui.CircleButton
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:src="@drawable/gyroscope"
            app:cb_color="@color/colorMain"
            app:cb_pressedRingWidth="8dip"
            android:id="@+id/gyroscope"
            android:layout_alignLeft="@+id/temperature"
            android:layout_alignStart="@+id/temperature"
            android:layout_below="@+id/title"/>

As you can see this attribute defines the color.

app:cb_color="@color/colorMain"

My Question is: How can I change this color programmaticly in this method?

public void testSensors() {
    if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {

    }
}

EDIT: setColor doesn't really work. There is this border left. (see image) Also: I'm using #616161 as the new color.

EDIT2: Found out, that the border is caused by the transparent circle thing which gets bigger, when the button is pressed. So basically removing this circle thing will be fine. I try to find an answer on my own :)

5
  • then you wont have the animation if you remove the circle right? Commented Aug 14, 2016 at 12:12
  • I don't really need the animation. So I could get rid of it. I'll try it :) Commented Aug 14, 2016 at 12:17
  • @Bhargav That's it! .setAnimationProgress(100) seems to disable the Circle! Thanks so much! Commented Aug 14, 2016 at 12:20
  • This is why you shouldn't be using deprecated github projects, why not just use the damn FloatingActionButton from the design lib? Commented Aug 14, 2016 at 12:33
  • @Bhargav Well, i could have used that. (Might change the design anyways) But i thought: "That's not the common use of the FAB" :) Commented Aug 19, 2016 at 12:10

3 Answers 3

1
CircleButton button;

button = (Button)findViewById(R.id.buttonId);


public void testSensors() {
    if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
         button.setColor(Color.parse("#000000"));
    }
}

If you are using normal button then

button.setBackgroundColor(ContextCompat.getColor(context,R.color.colorAccent));

You can use

1) Color.parse("#000000")

2) ContextCompat.getColor(context,R.color.yourColor)

Sign up to request clarification or add additional context in comments.

3 Comments

he already tried the setBackgroundColor and he doesn't like it. Plus if you read the source code the circleButton here extends an imageview, so the setbackgroundColor doesnt really work in this case.
Doesn't really work aswell. (See my new answer somewhere on this page)
@2Simpel ok Good Best Wishes
0

You can use the setColor() method of the circleButton, as you can see from the source code here .

So basically what you need to do is get a reference to your circle Button, using the findViewById method of your activity. then

public void testSensors() {
    if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
        myCircleButton.setColor(Color.parse("#000000"));
    }
}

Also if you are seeing the pressed ring, then that means the state of the button is somehow in the pressed state, so try setting it o false using the setPressed(false) method.

3 Comments

Doesn't really work aswell. (See my new answer somewhere around here)
@2Simpel try setting pressed as false, with cb.setPressed(false)
Sorry. Doesn't work... (Driving me crazy...) But i found out that I have to get rid of the little transparent "border" which gets bigger when pressed. In the question at the top I added a few things and an image. This is what it looks like right now. But anyway. Thank you :)
0

To answer this problem (if anyone has the same): You can set the animation to 100. This somehow disables the circle. For some reason the color of the button has now a fixed color (dark grey) but scince this is fine to me and I don't want to cry under my table, I just let it be and move on with my project.

mCircleButton.setAnimationProgress(100);

Thank you all so much for your help! :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.