Android学习之通过SeekBar调节布局背景颜色(RGB)
来源:互联网 发布:大乐透缩水软件 编辑:程序博客网 时间:2024/06/15 14:16
用RGB设置布局背景颜色的方法
relativeLayout.setBackgroundColor(Color.rgb(r,g,b));布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/RelativeLayout" tools:context="com.example.konghao.adjustcolor.MainActivity"> <LinearLayout android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="50dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/int_R" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <SeekBar android:id="@+id/R" android:layout_marginTop="10dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/int_G" android:layout_marginTop="30dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <SeekBar android:id="@+id/G" android:layout_marginTop="10dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/int_B" android:layout_marginTop="30dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <SeekBar android:id="@+id/B" android:layout_marginTop="10dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout></RelativeLayout>Main活动
public class MainActivity extends Activity { private RelativeLayout relativeLayout; private SeekBar color_R,color_G,color_B; private static int r = 0,g = 0,b = 0; private TextView int_r,int_g,int_b; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); relativeLayout = (RelativeLayout) findViewById(R.id.RelativeLayout); color_R = (SeekBar) findViewById(R.id.R); color_G = (SeekBar) findViewById(R.id.G); color_B = (SeekBar) findViewById(R.id.B); int_r = (TextView) findViewById(R.id.int_R); int_g = (TextView) findViewById(R.id.int_G); int_b = (TextView) findViewById(R.id.int_B); color_R.setMax(255); color_G.setMax(255); color_B.setMax(255); color_B.setProgress(0); color_G.setProgress(0); color_B.setProgress(0); color_R.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar,int progress, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { r = seekBar.getProgress(); String int_color_r = "R:" + String.valueOf(r); int_r.setText(int_color_r); relativeLayout.setBackgroundColor(Color.rgb(r,g,b)); } }); color_G.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { g = seekBar.getProgress(); String int_color_g = "G:" + String.valueOf(g); int_g.setText(int_color_g); relativeLayout.setBackgroundColor(Color.rgb(r,g,b)); } }); color_B.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { b = seekBar.getProgress(); String int_color_b = "B:" + String.valueOf(b); int_b.setText(int_color_b); relativeLayout.setBackgroundColor(Color.rgb(r,g,b)); } }); }}效果
阅读全文
0 0
- Android学习之通过SeekBar调节布局背景颜色(RGB)
- 芒果iOS开发之通过RGB值设置背景颜色
- android通过seekbar调节屏幕亮度
- (转)Android学习:SeekBar实现音量调节
- android 5.0及以上,seekbar thumb 透明效果出现父布局背景颜色的解决方法
- android 5.0及以上,seekbar thumb 透明效果出现父布局背景颜色的解决方法
- Android学习:SeekBar实现音量调节
- Android学习:SeekBar实现音量调节
- Android学习:SeekBar实现音量调节
- Android学习:SeekBar实现音量调节
- Android学习:SeekBar实现音量调节
- Android学习:SeekBar实现音量调节
- SeekBar中thumb的透明背景显示父布局颜色
- Android布局背景颜色设置
- Android 音量调节seekbar制作
- Android学习之SeekBar控件
- android学习笔记之SeekBar
- Android学习笔记之SeekBar
- tf相关接口说明
- 基于89C51的闪烁LED小灯设计
- python之__new__方法与实例化
- 2017.11.1
- Http最常见的错误代码
- Android学习之通过SeekBar调节布局背景颜色(RGB)
- P
- 125. Valid Palindrome
- javascript之Object.assign()痛点
- 面试题
- 7-zip 下lzma数据解压缩方式
- java三大部件之Listener
- sublime常用快捷键
- 线程的同步控制---信号量、互斥锁、条件变量