最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android通過SeekBar調(diào)節(jié)布局背景顏色

 更新時間:2022年04月25日 12:11:45   作者:Frank Kong  
這篇文章主要為大家詳細(xì)介紹了Android通過SeekBar調(diào)節(jié)布局背景顏色,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android通過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活動

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));
? ? ? ? ? ? }
? ? ? ? });
? ? }
}

效果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

依兰县| 西青区| 孝义市| 古丈县| 临沭县| 仪陇县| 简阳市| 新闻| 镇江市| 赣榆县| 大石桥市| 班玛县| 太仓市| 拜城县| 伊通| 通化县| 萝北县| 彰化市| 陕西省| 黄大仙区| 自贡市| 都匀市| 法库县| 洛川县| 炉霍县| 怀远县| 五峰| 内江市| 社旗县| 兴海县| 东乌珠穆沁旗| 吉木乃县| 皮山县| 鄂托克前旗| 磴口县| 武宣县| 西吉县| 延寿县| 安龙县| 措勤县| 饶阳县|