Android通過(guò)SeekBar調(diào)節(jié)布局背景顏色
本文實(shí)例為大家分享了Android通過(guò)SeekBar調(diào)節(jié)布局背景顏色的具體代碼,供大家參考,具體內(nèi)容如下
用RGB設(shè)置布局背景顏色的方法
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活動(dòng)
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)); ? ? ? ? ? ? } ? ? ? ? }); ? ? } }
效果
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android SeekBar控制視頻播放進(jìn)度實(shí)現(xiàn)過(guò)程講解
- Android?SeekBar充當(dāng)Progress實(shí)現(xiàn)兔兔進(jìn)度條Plus
- Android開(kāi)發(fā)雙向滑動(dòng)選擇器范圍SeekBar實(shí)現(xiàn)
- Android開(kāi)發(fā)自定義雙向SeekBar拖動(dòng)條控件
- Android開(kāi)發(fā)手冊(cè)SeekBar拖動(dòng)條使用實(shí)例
- Android自定義SeekBar實(shí)現(xiàn)滑動(dòng)驗(yàn)證且不可點(diǎn)擊
- Android SeekBar實(shí)現(xiàn)平滑滾動(dòng)
- Android SeekBar在刷新使用中需要注意的問(wèn)題
相關(guān)文章
Android Fragment動(dòng)態(tài)創(chuàng)建詳解及示例代碼
這篇文章主要介紹了Android Fragment動(dòng)態(tài)創(chuàng)建詳解的相關(guān)資料,并附實(shí)例代碼及實(shí)現(xiàn)效果圖,需要的朋友可以參考下2016-11-11Android實(shí)現(xiàn)雷達(dá)View效果的示例代碼
這篇文章主要介紹了Android實(shí)現(xiàn)雷達(dá)View效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06android用鬧鐘定時(shí)做http請(qǐng)求推送的解決方案
這篇文章主要為大家詳細(xì)介紹了android用鬧鐘定時(shí)做http請(qǐng)求推送的解決方案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01Android控件CardView實(shí)現(xiàn)卡片效果
這篇文章主要為大家詳細(xì)介紹了Android控件CardView實(shí)現(xiàn)卡片效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02android選擇視頻文件上傳到后臺(tái)服務(wù)器
這篇文章主要介紹了android選擇視頻文件上傳到后臺(tái)服務(wù)器的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04Android自定義View實(shí)現(xiàn)簡(jiǎn)單的圓形Progress效果
這篇文章主要介紹了Android自定義View實(shí)現(xiàn)簡(jiǎn)單的圓形Progress效果的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09Android ListView自動(dòng)顯示隱藏布局的實(shí)現(xiàn)方法
這篇文章主要介紹了Android ListView自動(dòng)顯示隱藏布局的實(shí)現(xiàn)方法的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09實(shí)現(xiàn)Android 獲取cache緩存的目錄路徑的方法
這篇文章主要介紹了實(shí)現(xiàn)Android 獲取cache緩存的目錄路徑的方法的相關(guān)資料,這里實(shí)現(xiàn)一個(gè)靜態(tài)類(lèi)來(lái)實(shí)現(xiàn)該功能,希望能幫助到大家,需要的朋友可以參考下2017-08-08