1、接口布局xml代码:

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:id="@+id/LinearLayout1"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical"
  7. tools:context=".MainActivity" >
  8.  
  9. <LinearLayout
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content" >
  12.  
  13. <TextView
  14. android:id="@+id/textView1"
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:text="当前值是:#000000" />
  18.  
  19. <TextView
  20. android:id="@+id/textView5"
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:padding="20px"
  24. android:width="100px"
  25. android:text="test" />
  26.  
  27. </LinearLayout>
  28.  
  29. <LinearLayout
  30. android:layout_width="match_parent"
  31. android:layout_height="wrap_content" >
  32.  
  33. <TextView
  34. android:id="@+id/textView2"
  35. android:layout_width="wrap_content"
  36. android:layout_height="wrap_content"
  37. android:layout_weight="1"
  38. android:text="红:" />
  39.  
  40. <SeekBar
  41. android:id="@+id/seekBar1"
  42. android:layout_width="match_parent"
  43. android:layout_height="wrap_content"
  44. android:layout_weight="1"
  45. android:max="255"
  46. android:padding="10px"
  47. android:progress="00" />
  48.  
  49. <EditText
  50. android:id="@+id/editText1"
  51. android:layout_width="wrap_content"
  52. android:layout_height="wrap_content"
  53. android:layout_weight="1"
  54. android:text="0"
  55. android:ems="10" >
  56.  
  57. <requestFocus />
  58. </EditText>
  59.  
  60. </LinearLayout>
  61.  
  62. <LinearLayout
  63. android:layout_width="match_parent"
  64. android:layout_height="wrap_content" >
  65.  
  66. <TextView
  67. android:id="@+id/textView3"
  68. android:layout_width="wrap_content"
  69. android:layout_height="wrap_content"
  70. android:layout_weight="1"
  71. android:text="绿" />
  72.  
  73. <SeekBar
  74. android:id="@+id/seekBar2"
  75. android:layout_width="match_parent"
  76. android:layout_height="wrap_content"
  77. android:max="255"
  78. android:progress="0"
  79. android:layout_weight="1" />
  80.  
  81. <EditText
  82. android:id="@+id/editText2"
  83. android:layout_width="wrap_content"
  84. android:layout_height="wrap_content"
  85. android:layout_weight="1"
  86. android:text="00"
  87. android:ems="10" />
  88.  
  89. </LinearLayout>
  90.  
  91. <LinearLayout
  92. android:layout_width="match_parent"
  93. android:layout_height="wrap_content" >
  94.  
  95. <TextView
  96. android:id="@+id/textView4"
  97. android:layout_width="wrap_content"
  98. android:layout_height="wrap_content"
  99. android:layout_weight="1"
  100. android:text="蓝" />
  101.  
  102. <SeekBar
  103. android:id="@+id/seekBar3"
  104. android:layout_width="match_parent"
  105. android:layout_height="wrap_content"
  106. android:max="255"
  107. android:progress="0"
  108. android:layout_weight="1" />
  109.  
  110. <EditText
  111. android:id="@+id/editText3"
  112. android:layout_width="wrap_content"
  113. android:layout_height="wrap_content"
  114. android:layout_weight="1"
  115. android:text="00"
  116. android:ems="10" />
  117.  
  118. </LinearLayout>
  119.  
  120. </LinearLayout>

2、java代码:

  1. package com.jwy;
  2.  
  3. import android.os.Bundle;
  4. import android.R.integer;
  5. import android.R.string;
  6. import android.app.Activity;
  7. import android.graphics.Color;
  8. import android.view.Menu;
  9. import android.widget.EditText;
  10. import android.widget.SeekBar;
  11. import android.widget.Toast;
  12. import android.widget.SeekBar.OnSeekBarChangeListener;
  13. import android.widget.TextView;
  14.  
  15. public class MainActivity extends Activity {
  16.  
  17. private TextView textView;
  18. private SeekBar seekBar1;
  19. private SeekBar seekBar2;
  20. private SeekBar seekBar3;
  21.  
  22. private EditText editText1;
  23. private EditText editText2;
  24. private EditText editText3;
  25.  
  26. @Override
  27. protected void onCreate(Bundle savedInstanceState) {
  28. super.onCreate(savedInstanceState);
  29. setContentView(R.layout.activity_main);
  30. textView = (TextView)findViewById(R.id.textView1);
  31. seekBar1 =(SeekBar)findViewById(R.id.seekBar1);
  32. seekBar2 =(SeekBar)findViewById(R.id.seekBar2);
  33. seekBar3 =(SeekBar)findViewById(R.id.seekBar3);
  34.  
  35. editText1=(EditText)findViewById(R.id.editText1);
  36. editText2=(EditText)findViewById(R.id.editText2);
  37. editText3=(EditText)findViewById(R.id.editText3);
  38.  
  39. seekBar1.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
  40. {
  41.  
  42. @Override
  43. public void onStopTrackingTouch(SeekBar seekBar)
  44. {
  45. // TODO Auto-generated method stub
  46. //Toast.makeText(MainActivity.this, "结束华滑动", Toast.LENGTH_SHORT).show();
  47. }
  48.  
  49. @Override
  50. public void onStartTrackingTouch(SeekBar seekBar)
  51. {
  52. // TODO Auto-generated method stub
  53. //Toast.makeText(MainActivity.this, "開始滑动", Toast.LENGTH_SHORT).show();
  54. }
  55.  
  56. @Override
  57. public void onProgressChanged(SeekBar seekBar, int progress,
  58. boolean fromUser)
  59. {
  60. // TODO Auto-generated method stub
  61. //Toast.makeText(MainActivity.this, "当前值是:"+progress, Toast.LENGTH_SHORT).show();
  62. String str = String.format("%1$02x", progress);
  63. editText1.setText(str);
  64. doWork();
  65. }
  66. });
  67.  
  68. seekBar2.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
  69. {
  70.  
  71. @Override
  72. public void onStopTrackingTouch(SeekBar seekBar)
  73. {
  74. // TODO Auto-generated method stub
  75.  
  76. }
  77.  
  78. @Override
  79. public void onStartTrackingTouch(SeekBar seekBar)
  80. {
  81. // TODO Auto-generated method stub
  82.  
  83. }
  84.  
  85. @Override
  86. public void onProgressChanged(SeekBar seekBar, int progress,
  87. boolean fromUser)
  88. {
  89. // TODO Auto-generated method stub
  90. //editText2.setText(Integer.toHexString(progress));
  91.  
  92. editText2.setText(String.format("%1$02x", progress));
  93. doWork();
  94. }
  95. });
  96.  
  97. seekBar3.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
  98. {
  99.  
  100. @Override
  101. public void onStopTrackingTouch(SeekBar seekBar)
  102. {
  103. // TODO Auto-generated method stub
  104.  
  105. }
  106.  
  107. @Override
  108. public void onStartTrackingTouch(SeekBar seekBar)
  109. {
  110. // TODO Auto-generated method stub
  111.  
  112. }
  113.  
  114. @Override
  115. public void onProgressChanged(SeekBar seekBar, int progress,
  116. boolean fromUser)
  117. {
  118. // TODO Auto-generated method stub
  119. //editText3.setText(Integer.toHexString(progress));
  120. editText3.setText(String.format("%1$02x", progress));
  121.  
  122. doWork();
  123. }
  124. });
  125. }
  126.  
  127. private void doWork()
  128. {
  129. String sTmp = editText1.getText().toString()+ editText2.getText().toString() + editText3.getText().toString();
  130. textView.setText("当前值是:#" + sTmp);
  131. TextView tView = (TextView)findViewById(R.id.textView5);
  132. tView.setBackgroundColor(Color.parseColor("#"+sTmp));
  133.  
  134. //tView.setBackgroundColor(Color.parseColor("#ff00"));
  135. }
  136.  
  137. @Override
  138. public boolean onCreateOptionsMenu(Menu menu) {
  139. // Inflate the menu; this adds items to the action bar if it is present.
  140. getMenuInflater().inflate(R.menu.main, menu);
  141. return true;
  142. }
  143.  
  144. }

使用SeekBar办Android调色板的更多相关文章

  1. Android --SeekBar的使用

    1. 效果图

  2. Android自定义Seekbar拖动条式样

    SeekBar拖动条可以由用户控制,进行拖动操作.比如,应用程序中用户需要对音量进行控制,就可以使用拖动条来实现. 1.SeekBar控件的使用 1.1SeekBar常用属性 SeekBar的常用属性 ...

  3. 【读书笔记《Android游戏编程之从零开始》】5.Android 游戏开发常用的系统控件(ProgressBar、Seekbar)

    3.7 ProgressBar ProgressBar类官方文档地址:http://developer.android.com/reference/android/widget/ProgressBar ...

  4. 7.Android之评分条RatingBar和拖动条SeekBar学习

    评分条RatingBar和拖动条SeekBar很常见,今天来学习下. (1)RatingBar评分条 如图: <RelativeLayout xmlns:android="http:/ ...

  5. Android SeekBar自定义使用图片和颜色显示

    案例使用的图片如下:                            1.在res/drawable目录下新增一个xml风格文件,seekbar_define_style.xml ? 1 2 3 ...

  6. android学习笔记八——SeekBar

    SeekBar——拖动条 拖动条(SeekBar)组件与ProgressBar水平形式的显示进度条类似,不过其最大的区别在于,拖动条可以由用户自己进行手工的调节,例如当用户需要调整播放器音量或者电影的 ...

  7. android之SeekBar控件用法

    MainActivity.java package com.example.mars_2400_seekbar; import android.support.v7.app.ActionBarActi ...

  8. Android 自学之拖动条SeekBar

    拖动条(SeekBar)和进度条非常相似,只是进度条采用颜色填充来表明进度完成的程度,而拖动条则通过滑块的位置来标识数值----而且拖动条允许用户拖动滑动块来改变值,因此拖动条通常用于对系统的某种数值 ...

  9. Android使用SeekBar时动态显示进度且随SeekBar一起移动

    最近有做一个android项目,里面有使用到在播放视频时可以跳播,同时动态显示播放时间.类似于下图 的效果,我只是抽取其中的一部分做展示,刚接到这个事时也是在网上一通找,最后没找到!而且还碰到有些朋友 ...

随机推荐

  1. Arrays.asList()

    1.数组--->List String[] ss={"abc","def","xyz","aaaaaaaa",&q ...

  2. T-SQL基础(7) - 透视,逆透视和分组集

    透视转换: use tempdb;if object_id('dbo.Orders', 'U') is not null drop table dbo.Orders;create table dbo. ...

  3. effective c++ 条款4 make sure that objects are initialized before they are used

    1 c++ 类的数据成员的初始化发生在构造函数前 class InitialData { public: int data1; int data2; InitialData(int a, int b) ...

  4. POJ 2155 D区段树

    POJ 2155  D区段树 思考:D区段树是每个节点设置一个段树树. 刚開始由于题目是求A[I,J],然后在y查询那直接ans^=Map[i][j]的时候没看懂.后面自己把图画出来了才理解. 由于仅 ...

  5. Android访问服务器(TOMCAT)乱码引发的问题

    1.浏览器往服务器发送的请求主要可分为2种:get.post:delete.head等不赘述. GET方式: 从浏览器上直接敲地址,最大特点就是参数直接跟在地址后面. POST方式:表单提交等. 2. ...

  6. sqlite3触发器的使用

    研究了一下osx下dock中应用的存储,位于~/Library/Application Support/Dock/下一个比較名字比較长的db文件里,之前简单的介绍过osx launchpad图标的删除 ...

  7. Linux下 高性能、易用、免费的ASP.NET服务器

    Linux下 高性能.易用.免费的ASP.NET服务器 http://www.jexus.org/#

  8. 它们的定义actionbar 并删除留空

    通过他们自己的定义actionbar布局变化actionbar样式,简单而美丽.但有一个细节需要注意的是,高分辨率的问题留空.一般720上述决议,下一次你发现,无论什么样的变化总是会有一个小的布局文件 ...

  9. JAVA 统计字符串中中文,英文,数字,空格的个数

    面试题:输入一行字符,分别统计出其中英文字母.中文字符.空格.数字和其它字符的个数 可以根据各种字符在Unicode字符编码表中的区间来进行判断,如数字为'0'~'9'之间,英文字母为'a'~'z'或 ...

  10. OpenCV2学习笔记(十四):基于OpenCV卡通图片处理

    得知OpenCV有一段时间.除了研究的各种算法的内容.除了从备用,据导游书籍和资料,尝试结合链接的图像处理算法和日常生活,第一桌面上(随着摄像头)完成了一系列的视频流处理功能.开发平台Qt5.3.2+ ...