Android color palette made of SeekBar and seekbarandroid

Source: Internet
Author: User

Android color palette made of SeekBar and seekbarandroid

1. xml code of the interface layout:

<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_height = "match_parent" android: orientation = "vertical" tools: context = ". mainActivity "> <LinearLayout android: layout_width =" match_parent "android: layout_height =" wrap_content "> <TextView android: id =" @ + id/textView1 "android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Current Value: #000000"/> <TextView android: id = "@ + id/textView5" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: padding = "20px" android: width = "100px" android: text = "test"/> </LinearLayout> <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 = "00"/> <EditText android: id = "@ + id/editText1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_weight = "1" android: text = "0" android: EMS = "10"> <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 android: 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_content" android: layout_weight = "1" android: text = "00" android: EMS = "10"/> </LinearLayout> <LinearLayout android: layout_width = "match_parent" android: layout_height = "wrap_content"> <TextView android: id = "@ + id/textView4" android: layout_width = "wrap_content" android: 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" android: 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 = "00" android: EMS = "10"/> </LinearLayout>

2. java code:

Package com. y; 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 sliding", 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, "the current value is:" + progress, Toast. LENGTH_SHORT ). show (); String str = String. format ("% 1 $ 02x", progress); editText1.setText (str); doWork () ;}}); updated (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); doWork () ;}}); seekBar3.setOnSeekBarChangeListener (new OnSeekBarChangeListener () {@ Overridepublic void onStopTrackingTouch) {// 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.getText (). toString (); textView. setText ("Current Value: #" + 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 ;}}



How can android adapt the circular seekbar designed by the image to different screens?

Two methods:
Add images of different sizes to different screens in the drawable folder
Only one image is added, but the size of the image is specified in dimens. xml. The image is scaled according to the size by code.


In android development, how does one set the minimum seekbar value?

Set OnSeekBarChangeListener first
Then:

@ Override
Public void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser ){
If (progress <70 ){
BrightBar. setProgress (70 );
Return;
}
}
 

Related Article

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.