使用SeekBar办Android调色板
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调色板的更多相关文章
- Android --SeekBar的使用
1. 效果图
- Android自定义Seekbar拖动条式样
SeekBar拖动条可以由用户控制,进行拖动操作.比如,应用程序中用户需要对音量进行控制,就可以使用拖动条来实现. 1.SeekBar控件的使用 1.1SeekBar常用属性 SeekBar的常用属性 ...
- 【读书笔记《Android游戏编程之从零开始》】5.Android 游戏开发常用的系统控件(ProgressBar、Seekbar)
3.7 ProgressBar ProgressBar类官方文档地址:http://developer.android.com/reference/android/widget/ProgressBar ...
- 7.Android之评分条RatingBar和拖动条SeekBar学习
评分条RatingBar和拖动条SeekBar很常见,今天来学习下. (1)RatingBar评分条 如图: <RelativeLayout xmlns:android="http:/ ...
- Android SeekBar自定义使用图片和颜色显示
案例使用的图片如下: 1.在res/drawable目录下新增一个xml风格文件,seekbar_define_style.xml ? 1 2 3 ...
- android学习笔记八——SeekBar
SeekBar——拖动条 拖动条(SeekBar)组件与ProgressBar水平形式的显示进度条类似,不过其最大的区别在于,拖动条可以由用户自己进行手工的调节,例如当用户需要调整播放器音量或者电影的 ...
- android之SeekBar控件用法
MainActivity.java package com.example.mars_2400_seekbar; import android.support.v7.app.ActionBarActi ...
- Android 自学之拖动条SeekBar
拖动条(SeekBar)和进度条非常相似,只是进度条采用颜色填充来表明进度完成的程度,而拖动条则通过滑块的位置来标识数值----而且拖动条允许用户拖动滑动块来改变值,因此拖动条通常用于对系统的某种数值 ...
- Android使用SeekBar时动态显示进度且随SeekBar一起移动
最近有做一个android项目,里面有使用到在播放视频时可以跳播,同时动态显示播放时间.类似于下图 的效果,我只是抽取其中的一部分做展示,刚接到这个事时也是在网上一通找,最后没找到!而且还碰到有些朋友 ...
随机推荐
- Nutch 二次开发parse纸
大约nutch基础知识可以参考lemo柱 nutch支持二次开发,为了满足搜索的准确性的问题,内容提取出来作为索引的内容,相应的是parse_text的数据.我使用的事nutch1.4 版本号,在cy ...
- sql基础之DDL(Data Definition Languages)
好久没写SQL语句了,复习一下. DDL数据定义语言,DDL定义了不同的数据段.数据库.表.列.索引等数据库对象的定义.经常使用的DDL语句包含create.drop.alter等等. 登录数据:my ...
- CacheManager
.Net缓存管理框架CacheManager Cache缓存在计算机领域是一个被普遍使用的概念.硬件中CPU有一级缓存,二级缓存, 浏览器中有缓存,软件开发中也有分布式缓存memcache, redi ...
- Effective C++笔记05:实现
条款26:尽可能延后变量定义式的出现时间 博客地址:http://blog.csdn.net/cv_ronny 转载请注明出处! 有些对象,你可能过早的定义它,而在代码运行的过程中发生了导常,造成了開 ...
- 【软件使用技巧】PL/SQL Developer实现双击table询
二手plsql都知道,在表名默认双击[开展/关闭]. 习惯了MySql Workbench要么Sqlserver Management Studio无法适应其他管理工具. 直接在溶液: Tools - ...
- NET功能集
NET功能集 目录 1. ObsoleteAttribute2. 设置默认值属性: DefaultValueAttribute3. DebuggerBrowsableAttribute4. ??运算符 ...
- Redis被攻击
记一次Redis被攻击的事件 最近几个月非常忙,所以很少有时间写博客,这几天终于闲了一些,于是就在整理平时的一些笔记.恰好这几天Redis服务器发生了问题,就记录一下. 我司有两款分别是2B和2C ...
- MEF初体验之十一:查询组合容器
查询组合容器 组合容器暴露了几个get exports的重载方法和导出对象和对象集合.你需要注意下面的行为: 当请求单个对象实例时,如果未发现导出,一个异常将被抛出 当请求单个对象实例时,如果发现超过 ...
- Sqlmap渗透测试是常用语句
1.获取站点信息 sqlmap.py -u http://.../ 2.获取站点的数据库信息 sqlmap.py -u http://../ --dbs 3.获取数据库DataBaseTest下的表 ...
- Linux通过使用Sambaserver示例
Linux通过使用Sambaserver示例 实验环境: Vbox下一个.Rehat5虚拟机 使用sambaserver 目的:使用sambaserver将文件上传到server上 [root@rh5 ...