1、接口布局xml代码:

<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="当前值是:#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="红:" /> <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="绿" /> <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="蓝" /> <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> </LinearLayout>

2、java代码:

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()
{ @Override
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
//Toast.makeText(MainActivity.this, "结束华滑动", Toast.LENGTH_SHORT).show();
} @Override
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
//Toast.makeText(MainActivity.this, "開始滑动", Toast.LENGTH_SHORT).show();
} @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
// TODO Auto-generated method stub
//Toast.makeText(MainActivity.this, "当前值是:"+progress, Toast.LENGTH_SHORT).show();
String str = String.format("%1$02x", progress);
editText1.setText(str);
doWork();
}
}); seekBar2.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{ @Override
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub } @Override
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub } @Override
public 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()
{ @Override
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub } @Override
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub } @Override
public 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("当前值是:#" + 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;
} }

使用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. git tag使用

    #git tag command git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>]       ...

  2. DataGridView大扩展——显示行号

    原文 DataGridView大扩展——显示行号 在DataGridView 的实际使用中,经常需要标示出行号,这样可以比较醒目地看到当前信息.不过DataGridView 在绘制 DataGridV ...

  3. 用Linux/Unix命令把十六进制转换成十进制(转)

    那天写个脚本,需要把十六进制的数字转成十进制的打出来,发现不知道要怎么弄,搜一下,原来还是很简单的,比用C语言什么的容易多了,就一些现成的命令就解决了. 先列两种简单的方法: 1) echo 自己就能 ...

  4. android看不见main函数怎么办?程序异常了,能够不提示“xxx软件停止执行”吗?

    今天遇到了这个问题,分享一下解决方式. android没有main 函数,自然也就不存在main里面加入异常处理来实现全局异常捕获的方案.那android程序有全局异常补货的解决方式吗? 答案是有的: ...

  5. 在 VS 类库项目中 Add Service References 和 Add Web References 的区别

    原文:在 VS 类库项目中 Add Service References 和 Add Web References 的区别 出身问题: 1.在vs2005时代,Add Web Reference(添加 ...

  6. 构建安全的Xml Web Service系列之wse之错误代码详解

    原文:构建安全的Xml Web Service系列之wse之错误代码详解 WSE3.0现在还没有中文版的可以下载,使用英文版的过程中,难免会遇到各种各样的错误,而面对一堆毫无头绪的错误异常,常常会感到 ...

  7. ArcSDE SDK For Java二次开发介绍、演示样例

    在一个工作中,遇到了须要java后台来查询ArcGIS 中用到的Oracle数据库空间数据,因为对ArcGIS空间数据首次接触,仅仅知道Oracle能够使用ST_GEOMETRY字段存储,例如以下图 ...

  8. iOS 9 新特性

    这篇文章介绍了iOS9开发相关的简介,现在发布的设备都会搭载iOS9.这篇文章也列出了详细描述新特性的文章. iPad多线程增强 iOS9使用Slider Over, Split View, Pict ...

  9. Android-管理Activity生命周期 -重新创建Activity

    按照正常的app行为,很少情况下activity会销毁,只有当用户点击了返回按钮或者activity通过调用finish()发出销毁信号.系统也有可能销毁activity如果它是停止状态并且很久没有使 ...

  10. 导致Asp.Net站点重启的10个原因

    原文:导致Asp.Net站点重启的10个原因 Asp.Net站点有时候会莫名其妙的重启,什么原因导致的却不得而知,经过一番折腾后,我总结了导致Asp.Net站点重启的10个原因 1. 回收应用程序池会 ...