Skip to content Skip to sidebar Skip to footer

How To Add Color Picker In Application?

I have developed an Application , which uses screen as a Slate and finger as a Chalk, which is working properly. But I want to use different color types for chalk. Here is my Code:

Solution 1:

You can take the sample in your android folder's..

For the color picker go to in this folder:

android/samples/android-YOURS_VERSION/ApiDemos

Solution 2:

Use this, review this code. than your problem will be solve

package com.example.changecolor;
      import android.app.Activity;
      import android.content.pm.PackageInfo;
      import android.content.pm.PackageManager;
      import android.graphics.Color;
      import android.os.Bundle;
      import android.view.Menu;
      import android.view.MenuItem;
      import android.view.View;
      import android.widget.Button;
      import android.widget.LinearLayout;
      import android.widget.TextView;


 publicclassMainActivityextendsActivityimplementsView.OnClickListener, UberColorPickerDialog.OnColorChangedListener {

privateintmColor=0xFFFF0000;

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Write the version numberPackageManagerpm= getPackageManager();
    StringversionName="";
    try {
        PackageInfopi= pm.getPackageInfo("com.keithwiley.android.ubercolorpickerdemo", 0);
        versionName = pi.versionName;
    }
    catch (Exception e) {
    }
    TextViewtextView= (TextView) findViewById(R.id.version);
    textView.setText(versionName);

    //Initialize the sample
    ((LinearLayout) findViewById(R.id.LinearLayout)).setBackgroundColor(mColor);
    float hsv[] = newfloat[3];
    Color.colorToHSV(mColor, hsv);
    if (UberColorPickerDialog.isGray(mColor))
        hsv[1] = 0;
    if (hsv[2] < .5)
        ((TextView) findViewById(R.id.sample)).setTextColor(Color.WHITE);
    else ((TextView) findViewById(R.id.sample)).setTextColor(Color.BLACK);

    //Set up the buttonsButtonbutton= (Button) findViewById(R.id.colorPickerWithTitle);
    button.setOnClickListener(this);

    button = (Button) findViewById(R.id.colorPickerWithToast);
    button.setOnClickListener(this);
}

protectedvoidonPause() {
    super.onPause();
}

protectedvoidonResume() {
    super.onResume();
}

publicbooleanonCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    returntrue;
}

publicbooleanonPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    returntrue;
}

publicbooleanonOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    }

    returnsuper.onOptionsItemSelected(item);
}

publicvoidonClick(View v) {
    if (v.getId() == R.id.colorPickerWithTitle)
        newUberColorPickerDialog(this, this, mColor, true).show();
    if (v.getId() == R.id.colorPickerWithToast)
        newUberColorPickerDialog(this, this, mColor, false).show();
}

publicvoidcolorChanged(int color) {
    ((LinearLayout) findViewById(R.id.LinearLayout)).setBackgroundColor(mColor=color);

    float hsv[] = newfloat[3];
    Color.colorToHSV(mColor, hsv);
    //if (UberColorPickerDialog.isGray(mColor))//  hsv[1] = 0;if (hsv[2] < .5)
        ((TextView) findViewById(R.id.sample)).setTextColor(Color.WHITE);
    else ((TextView) findViewById(R.id.sample)).setTextColor(Color.BLACK);
   }
  }

And use the color picker class

Post a Comment for "How To Add Color Picker In Application?"