Android Color Toner made with Seekbar

Source: Internet
Author: User

1. Interface Layout XML code:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:id=" @+id/linearlayout1 "android:layout_width=" Match_parent "Android:layout_hei ght= "match_parent" android:orientation= "vertical" tools:context= ". Mainactivity "> <linearlayout android:layout_width=" match_parent "android:layout_height=" Wrap_conte            NT "> <textview android:id=" @+id/textview1 "android:layout_width=" Wrap_content " android:layout_height= "Wrap_content" android:text= "Current value is: #000000"/> <textview Andro            Id:id= "@+id/textview5" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:padding= "20px" android:width= "100px" android:text= "test"/> &LT;/LINEARLAYOUT&G    T <linearlayout android:layout_width= "Match_parent" android:layout_height= "WRap_content "> <textview android:id=" @+id/textview2 "android:layout_width=" wrap_content        "Android:layout_height=" Wrap_content "android:layout_weight=" 1 "android:text=" Red: "/> <seekbar android:id= "@+id/seekbar1" android:layout_width= "Match_parent" Android : layout_height= "Wrap_content" android:layout_weight= "1" android:max= "255" android:padding = "10px" android:progress= "xx"/> <edittext android:id= "@+id/edittext1" Andro            Id:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_weight= "1" android:text= "0" android:ems= "ten" > <requestfocus/> </EditText> </ linearlayout> <linearlayout android:layout_width= "match_parent" android:layout_height= "wrap_content "> <textviEW android:id= "@+id/textview3" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_weight= "1" android:text= "green"/> <seekbar Androi            D:id= "@+id/seekbar2" android:layout_width= "match_parent" android:layout_height= "Wrap_content"            android:max= "255" android:progress= "0" android:layout_weight= "1"/> <edittext Android:id= "@+id/edittext2" android:layout_width= "wrap_content" android:layout_height= "Wrap_c Ontent "android:layout_weight=" 1 "android:text=" xx "android:ems="/> </linear         layout> <linearlayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" > <textview android:id= "@+id/textview4" android:layout_width= "Wrap_content" Android Oid:layout_height= "Wrap_Content "android:layout_weight=" 1 "android:text=" Blue "/> <seekbar android:id=" @+id/seekbar3 "android:layout_width=" match_parent "android:layout_height=" Wrap_content "a            ndroid:max= "255" android:progress= "0" android:layout_weight= "1"/> <edittext Android:id= "@+id/edittext3" android:layout_width= "wrap_content" android:layout_height= "wrap_content "android:layout_weight=" 1 "android:text=" xx "android:ems="/> </linearlayout ></LinearLayout>

2. Java code:

Package Com.jwy;import Android.os.bundle;import Android. R.integer;import Android. R.string;import Android.app.activity;import Android.graphics.color;import Android.view.menu;import Android.widget.edittext;import Android.widget.seekbar;import Android.widget.toast;import Android.widget.seekbar.onseekbarchangelistener;import Android.widget.textview;public class MainActivity extends Activity {private TextView textview;private SeekBar seekbar1;private SeekBar seekbar2;private SeekBar seekbar3;private    EditText edittext1;private EditText edittext2;private EditText editText3;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        TextView = (TextView) Findviewbyid (R.ID.TEXTVIEW1);        SeekBar1 = (SeekBar) Findviewbyid (R.ID.SEEKBAR1);        SeekBar2 = (SeekBar) Findviewbyid (R.ID.SEEKBAR2);                SeekBar3 = (SeekBar) Findviewbyid (R.ID.SEEKBAR3); edittext1= (EditText) FINDVIEWBYid (R.ID.EDITTEXT1);        Edittext2= (EditText) Findviewbyid (R.ID.EDITTEXT2);                edittext3= (EditText) Findviewbyid (R.ID.EDITTEXT3); Seekbar1.setonseekbarchangelistener (New Onseekbarchangelistener () {@Overridepublic void Onstoptrackingtouch ( SeekBar SeekBar) {//TODO auto-generated method Stub//toast.maketext (Mainactivity.this, "End China Slide", toast.length_short). Show ();} @Overridepublic void Onstarttrackingtouch (SeekBar SeekBar) {//TODO auto-generated method Stub//toast.maketext ( Mainactivity.this, "Start sliding", Toast.length_short). Show (); @Overridepublic void onprogresschanged (SeekBar SeekBar, int progress,boolean fromuser) {//TODO auto-generated method Stub//toast.maketext (Mainactivity.this, "Current value is:" +progress, Toast.length_short). Show (); String str = String.Format ("%1$02x", Progress); Edittext1.settext (str);                DoWork ();}}); Seekbar2.setonseekbarchangelistener (New Onseekbarchangelistener () {@Overridepublic void Onstoptrackingtouch ( SeekBar SeekBar) {//TODO auto-generated MethoD stub} @Overridepublic void Onstarttrackingtouch (SeekBar SeekBar) {//TODO auto-generated method stub} @Overridepublic void Onprogresschanged (SeekBar SeekBar, int progress,boolean fromuser) {//TODO auto-generated method stub//                Edittext2.settext (integer.tohexstring (progress)); Edittext2.settext (String.Format ("%1$02x", Progress));d owork ();}); Seekbar3.setonseekbarchangelistener (New Onseekbarchangelistener () {@Overridepublic void Onstoptrackingtouch (SeekB Ar seekBar) {//Todo auto-generated method stub} @Overridepublic void Onstarttrackingtouch (SeekBar seekBar) {//TODO auto-generated method stub} @Overridepublic void Onprogresschanged (SeekBar SeekBar, int progress,boolean fromuser) {// TODO auto-generated Method Stub//edittext3.settext (Integer.tohexstring (progress)); Edittext3.settext (String.Format ("%1$02x", Progress));    DoWork ();}}); } private void DoWork () {String sTmp = Edittext1.gettext (). ToString () + Edittext2.gettext (). ToString () + edittext3.ge Ttext (). toString (); TextView.SetText ("Current value is: #" + sTmp); TextView TView = (TextView) Findviewbyid (R.ID.TEXTVIEW5); Tview.setbackgroundcolor (Color.parsecolor ("#" +stmp));//        Tview.setbackgroundcolor (Color.parsecolor ("#ff00"));}  @Override public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the action Bar        If it is present.        Getmenuinflater (). Inflate (R.menu.main, menu);    return true; }    }


Android Color Toner made with Seekbar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.