S.M_Emamian
S.M_Emamian

Reputation: 17383

setTextColor and getcolor from holocolorpicker

I am using holocolorpicker lib. I would like to get color it and set it to a textview, but colorpicker returns an invalid color(the return color is different with my color). ex :

enter image description here

my text on textview (masoud) has a different color with color circle !

public class MainActivity extends ActionBarActivity implements OnColorChangedListener  {
    TextView txt ; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ColorPicker picker = (ColorPicker) findViewById(R.id.picker);
//      SVBar svBar = (SVBar) findViewById(R.id.svbar);
        OpacityBar opacityBar = (OpacityBar) findViewById(R.id.opacitybar);
        SaturationBar saturationBar = (SaturationBar) findViewById(R.id.saturationbar);
        ValueBar valueBar = (ValueBar) findViewById(R.id.valuebar);

//      picker.addSVBar(svBar);
        picker.addOpacityBar(opacityBar);
        picker.addSaturationBar(saturationBar);
        picker.addValueBar(valueBar);

        //To get the color
        picker.getColor();

        //To set the old selected color u can do it like this
        picker.setOldCenterColor(picker.getColor());
        // adds listener to the colorpicker which is implemented
        //in the activity
        picker.setOnColorChangedListener(this);

        //to turn of showing the old color
        picker.setShowOldCenterColor(false);

        //adding onChangeListeners to bars
//      opacitybar.setOnOpacityChangeListener(new OnOpacityChangeListener)
//      valuebar.setOnValueChangeListener(new OnValueChangeListener …)
//      saturationBar.setOnSaturationChangeListener(new OnSaturationChangeListener …)   

        txt = (TextView)findViewById(R.id.txt);
    }

    @Override
    public void onColorChanged(int color) {
        // TODO Auto-generated method stub

        final int c = color ;
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub

                txt.setTextColor(Color.rgb(c, c, c));
            }
        }, 2000);

    }

}

my layout.xml :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.ex9_holocolorpicker.MainActivity" >

    <com.larswerkman.holocolorpicker.ColorPicker
        android:id="@+id/picker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>


    <com.larswerkman.holocolorpicker.OpacityBar
        android:id="@+id/opacitybar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <com.larswerkman.holocolorpicker.SaturationBar
        android:id="@+id/saturationbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <com.larswerkman.holocolorpicker.ValueBar
        android:id="@+id/valuebar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>  

    <TextView 
        android:id="@+id/txt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="masoud"
        />
</LinearLayout>

Upvotes: 1

Views: 1232

Answers (1)

TehCoder
TehCoder

Reputation: 209

Color.rgb(c,c,c) means that you set c as the value for RED GREEN and BLUE.

You could use Color.rgb(Color.red(c),Color.green(c),Color.blue(c)); for example :)

EDIT: more here http://developer.android.com/reference/android/graphics/Color.html

EDIT2: setTextColor(c) does it to :p (thx to Vikram)

Upvotes: 1

Related Questions