Screen
Layout
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/widget35"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red"
android:layout_x="42px"
android:layout_y="30px"></TextView>
<SeekBar android:id="@+id/SeekBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="255"
android:minWidth="250px"
android:layout_x="42px"
android:layout_y="55px">
</SeekBar>
<TextView
android:id="@+id/widget36"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Green"
android:layout_x="42px"
android:layout_y="130px"></TextView>
<SeekBar android:id="@+id/SeekBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="255"
android:minWidth="250px"
android:layout_x="42px"
android:layout_y="155px">
</SeekBar>
<TextView
android:id="@+id/widget37"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue"
android:layout_x="42px"
android:layout_y="230px"></TextView>
<SeekBar android:id="@+id/SeekBar3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="255"
android:minWidth="250px"
android:layout_x="42px"
android:layout_y="255px">
</SeekBar>
<TextView
android:id="@+id/txtMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enrichware"
android:layout_x="42px"
android:layout_y="330px"></TextView>
</AbsoluteLayout>
Java Code
package com.color;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
public class ChangeColor extends Activity {
SeekBar redBar;
SeekBar greenBar;
SeekBar blueBar;
TextView msg;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
msg = (TextView) findViewById(R.id.txtMessage);
redBar = (SeekBar) findViewById(R.id.SeekBar1);
greenBar = (SeekBar) findViewById(R.id.SeekBar2);
blueBar = (SeekBar) findViewById(R.id.SeekBar3);
redBar.setOnSeekBarChangeListener((OnSeekBarChangeListener) new redClicker());
greenBar.setOnSeekBarChangeListener((OnSeekBarChangeListener) new greenClicker());
blueBar.setOnSeekBarChangeListener((OnSeekBarChangeListener) new blueClicker());
}
class redClicker implements SeekBar.OnSeekBarChangeListener {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
try {
msg.setTextColor(Color.rgb(redBar.getProgress(), greenBar.getProgress(), blueBar.getProgress()));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
class greenClicker implements SeekBar.OnSeekBarChangeListener {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
try {
msg.setTextColor(Color.rgb(redBar.getProgress(), greenBar.getProgress(), blueBar.getProgress()));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
class blueClicker implements SeekBar.OnSeekBarChangeListener {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
try {
msg.setTextColor(Color.rgb(redBar.getProgress(), greenBar.getProgress(), blueBar.getProgress()));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
}
1 comments:
Thanks for sharing as it is an excellent post would love to read your future post
-----------------------------------------------------------------------------
Php Web Development India :: & :: Php Web Application Development
Post a Comment