Android中的调色板功能的实现
来源:互联网 发布:手机变脸软件 编辑:程序博客网 时间:2024/06/06 13:25
实现调色板的详细步骤
1、 大体步骤: 1) 第一步在activity_main.xml中声明三个进度条(seekBar)和三个表示颜色的Textview控件。大容器用的布局是Linelayout,然后将显示颜色字体的textview和seekbar嵌套Linelayout布局。 2) 第二步:在mainactivity.java中设置监听器(OnSeekBarChangeListener),实现它的三个未实现的方法,在方法里面获取当前进度条的数值,用设置背景颜色的方法显示颜色,再用一个封装的将数值转化成十六进制的方法将其显示在textview中。2、 详细步骤: 1. 在activitity_main.xml中的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.test.colorchanged.MainActivity" > <com.test.colorchanged.titlelayout android:layout_width="match_parent" android:layout_height="wrap_content" ></com.test.colorchanged.titlelayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/txt1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:text="红色" /> <SeekBar android:id="@+id/seekbar1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:max="255" android:progress="0" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/txt2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="绿色" /> <SeekBar android:id="@+id/seekbar2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="20dp" android:max="255" android:progress="0" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/txt3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="蓝色" /> <SeekBar android:id="@+id/seekbar3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="20dp" android:max="255" android:progress="0" /> </LinearLayout><RelativeLayout android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="fill_parent" > <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30dp" /> <EditText android:id="@+id/edtxt" android:layout_width="fill_parent" android:layout_below="@+id/text1" android:layout_height="fill_parent" /></RelativeLayout></LinearLayout>
2、在Mainactivity中添加seekbar的监听类:
package com.test.colorchanged;import org.w3c.dom.Text;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.Window;import android.widget.EditText;import android.widget.SeekBar;import android.widget.SeekBar.OnSeekBarChangeListener;import android.widget.TextView;public class MainActivity extends Activity { private SeekBar seekbar1,seekbar2,seekbar3; private EditText edtxt; private TextView txt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); seekbar1 = (SeekBar) findViewById(R.id.seekbar1); seekbar2 =(SeekBar) findViewById(R.id.seekbar2); seekbar3 =(SeekBar) findViewById(R.id.seekbar3); edtxt=(EditText) findViewById(R.id.edtxt); txt=(TextView) findViewById(R.id.text1); seekbar1.setOnSeekBarChangeListener(new listener()); seekbar2.setOnSeekBarChangeListener(new listener()); seekbar3.setOnSeekBarChangeListener(new listener()); } class listener implements OnSeekBarChangeListener{ //进度条改变 public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { // TODO Auto-generated method stub int progress1=seekbar1.getProgress(); int progress2=seekbar2.getProgress(); int progress3=seekbar3.getProgress(); edtxt.setBackgroundColor(Color.rgb(progress1, progress2, progress3)); txt.setText(Integer.toHexString(progress1)+Integer.toHexString(progress2)+Integer.toHexString(progress3)); } @Override //开始拖动 public void onStartTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub int progress1=seekbar1.getProgress(); int progress2=seekbar2.getProgress(); int progress3=seekbar3.getProgress(); edtxt.setBackgroundColor(Color.rgb(progress1, progress2, progress3)); txt.setText(Integer.toHexString(progress1)+Integer.toHexString(progress2)+Integer.toHexString(progress3)); } @Override //停止拖动 public void onStopTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub int progress1=seekbar1.getProgress(); int progress2=seekbar2.getProgress(); int progress3=seekbar3.getProgress(); edtxt.setBackgroundColor(Color.rgb(progress1, progress2, progress3)); txt.setText(Integer.toHexString(progress1)+Integer.toHexString(progress2)+Integer.toHexString(progress3)); } } @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; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}
好的,现在就已经实现了三个调色板的功效了,还可以有一个透明度的seekbar,这里小编就没有写啦,还是很简单的,不知道有没有细心的读者注意到,你们写出来的揭界面跟小编的不太一样呐,,对的,就是我们默认的标题栏不太一样,我这里用了一个自定义的控件。好的,小编的下一篇博客会讲怎样自己这只一个漂亮的标题栏而不哟个默认的标题栏的。
0 0
- Android中的调色板功能的实现
- flex调色板功能实现
- 调色板的实现
- 调色板的简单实现
- android Palette调色板的使用方法
- Android Palette 调色板 的使用
- 截图功能实现(六)如何实现自定义调色板
- android中的更新功能实现
- Android 颜色资源UI的调色板颜色
- android中的属性动画暂停功能的实现
- Qt中的调色板
- Unity:实现调色板
- Android 5.0中的FDE功能实现
- Android中的一键退出功能实现
- Android中的一键退出功能实现
- android 控件 调色板 Palette
- Android调色板的开发与RGB颜色的使用
- Android学习之5.0三姐妹调色板palette的使用
- C++关于堆上与栈上分配对象
- leetcode交换相邻的两个节点的值
- 用Python做投资-关于term spread
- 内存初始化(上)
- Laxcus大数据管理系统单机集群版
- Android中的调色板功能的实现
- 71. Simplify Path
- emacs注释快捷键
- 四种C#实现播放声音的方法,如DirectX ,SoundPlayer, Windows Media Player
- pandas处理excel数据经验
- 从零开始学_JavaScript_系列(31)——事件代理/事件委托
- 哈夫曼树的实现
- MySQL 字符集与校对规则
- HDU 1269 迷宫城堡 (Tarjan 算法)