Create a Simple Color Picker Android App [Seekbar Support]

This post will let you create a simple Color picker android application which will return the HEX code from the values set by R,G, and B labeled seekbars. In this application you can not only get the HEX value of the color generated but you can also set the color as the application background. This app is created by 3 seekbars and 1 EditText and 2 buttons.

The value of the seekbars are extracted form the getProgress() method. and the obtained values from R,G, and B are converted to hex using toHexString() method and finally they are concatenated together for the HEX code of the RGB.

Demo:



The Hex Code generated when tapped on the generate Button


The Background Color changes with corresponding value of Hex code when tapped on Set It 


Lets have a glimpse on the basic concepts of the MainActivity.java
Fetching values from the Seekbars
r=sb1.getProgress();
g=sb2.getProgress();
b=sb3.getProgress(); 

Setting the value of the Hex Code box from the Seekbars
et.setText("#"+Integer.toHexString(r)+Integer.toHexString(g)+Integer.toHexString(b));

Changing the Background color from the Hex Code
rl.setBackgroundColor(Color.rgb(r, g, b));
/* rl is the relative layout variable which was declared on the onCreate method

rl=(RelativeLayout)findViewById(R.id.layout1); */

Alternatively you can download the whole code here.
Found Bugs, please report us, we will be glad to fix them ! :D

Comments

Post a Comment

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Hackerrank Modified Kaprekar Numbers Solution

Bit Stuffing Code Implementation in Java