用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;
    }

}
时间: 2024-07-30 09:39:25

用SeekBar做的Android颜色调色器的相关文章

做一个Android音乐播放器是遇到的一些困难

最近再做一个安卓的音乐播放器,是实验室里学长派的任务,我是在eclipse上进行开发的,由于没有android的基础,所以做起来困难重重. 首先是布局上的困难 1.layout里的控件属性不熟悉 2.想做一个音乐列表做不出来知道要用Listview控件,网上也找了许多的音乐播放器的代码,但导入项目中总会出错,所以想在这里请教各位 3.除了布局有困难外,实现相关功能也有困难,由于基础不行所以我并不想也做不出网上音乐播放器那么多的功能,我只想要我的播放器有播放,暂停,上一曲,下一曲的效果就行了,这还

Android 颜色渲染(十) ComposeShader组合渲染

版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] Android 颜色处理(十) ComposeShader组合渲染 public ComposeShader(Shader shaderA,Shader shaderB, Xfermode mode) Parameters shaderA 渲染器A,Shader及其子类对象 shaderB 渲染器B,Shader及其子类对象 mode  两种渲染器组合的模式,Xfermode对象 public ComposeShader(S

Android 颜色渲染(五) LinearGradient线性渲染

版权声明:本文为博主原创文章,未经博主允许不得转载. Android 颜色处理(五) LinearGradient线性渲染 相信很多人都看过歌词同步的效果, 一是竖直方向的滚动,另一方面是水平方面的歌词颜色渐变点亮效果,这种效果怎么做呢? 这就需要用到LinearGradient线性渲染,下面还是先看具体的使用: LinearGradient有两个构造函数; public LinearGradient(float x0, float y0, float x1, float y1, int[] c

Android 基于ijkplayer+Rxjava+Rxandroid+Retrofit2.0+MVP+Material Design的android万能播放器aaa

MDPlayer万能播放器 MDPlayer,基于ijkplayer+Rxjava+Rxandroid+Retrofit2.0+MVP+Material Design的android万能播放器,可以播放本地和在线视频,可以浏览宅男杀手妹纸图片,UI设计遵循 Material Design. GitHub地址:https://github.com/Dawish/MDPlayer UI浏览:         1.UI设计: 列表使用RecyclerView,item为CardView并设置rippl

Vitamio打造自己的Android万能播放器

前言 虽然Android已经内置了VideoView组件和MediaPlayer类来支持开发视频播放器,但支持格式.性能等各方面都十分有限,这里与大家一起利用免费的Vitamio来打造属于自己的Android万能播放器! 声明 欢迎转载,但请保留文章原始出处:) 石攻玉 :http://www.cnblogs.com/stone4/ 正文 一.实现目标 1.1 支持格式 支持主流的视音频格式:mp3/mp4/mkv/avi/3gp/rmvb/mov/flv等. 1.2 支持功能 1.2.1 当然

Android图片查看器(图片可移动、缩放)

要实现图片在手指点击后移动和缩放有好几种方法,在这里是通过onTouch来实现的. 实例代码如下: 首先是在View中有一个ImageView <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_paren

Android 颜色渲染(八) SweepGradient扫描/梯度渲染

版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] Android 颜色处理(八) SweepGradient 扫描/梯度渲染 为什么什么叫扫描渲染呢?  相信大家都看过雷达扫描的效果,尤其是在安全软件中.   public SweepGradient(float cx, float cy, int[] colors, float[] positions) Parameters: cx 渲染中心点x 坐标 cy 渲染中心y 点坐标 colors 围绕中心渲染的颜色数组,至少要

Android 颜色渲染(四) BitmapShader位图渲染

版权声明:本文为博主原创文章,未经博主允许不得转载. Android 颜色处理(四) BitmapShader位图渲染 public   BitmapShader(Bitmap bitmap,Shader.TileMode tileX,Shader.TileMode tileY) 调用这个方法来产生一个画有一个位图的渲染器(Shader). bitmap   在渲染器内使用的位图 tileX      The tiling mode for x to draw the bitmap in.  

Android 颜色渲染(九) PorterDuff及Xfermode详解

版权声明:本文为博主原创文章,未经博主允许不得转载. Android 颜色渲染(九)  PorterDuff及Xfermode详解 之前已经讲过了除ComposeShader之外Shader的全部子类, 在讲ComposeShader(组合渲染)之前,  由于构造ComposeShader需要 PorterDuffXfermode或者PorterDuff.Mode作为参数,所以在此先详细地了解下这两个类的作用,这对之后的绘图会有很大的帮 助: 在讲具体的使用之前补充一点知识,这就是 Proter