iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Android怎么通过SeekBar调节布局背景颜色
  • 707
分享到

Android怎么通过SeekBar调节布局背景颜色

2023-06-30 09:06:12 707人浏览 泡泡鱼
摘要

本文小编为大家详细介绍“Android怎么通过SeekBar调节布局背景颜色”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android怎么通过SeekBar调节布局背景颜色”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习

本文小编为大家详细介绍“Android怎么通过SeekBar调节布局背景颜色”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android怎么通过SeekBar调节布局背景颜色”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

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

效果

Android怎么通过SeekBar调节布局背景颜色

读到这里,这篇“Android怎么通过SeekBar调节布局背景颜色”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注编程网精选频道。

--结束END--

本文标题: Android怎么通过SeekBar调节布局背景颜色

本文链接: https://www.lsjlt.com/news/328076.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android通过SeekBar调节布局背景颜色
    本文实例为大家分享了Android通过SeekBar调节布局背景颜色的具体代码,供大家参考,具体内容如下 用RGB设置布局背景颜色的方法 relativeLayout.setBack...
    99+
    2024-04-02
  • Android怎么通过SeekBar调节布局背景颜色
    本文小编为大家详细介绍“Android怎么通过SeekBar调节布局背景颜色”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android怎么通过SeekBar调节布局背景颜色”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习...
    99+
    2023-06-30
  • pycharm怎么调背景颜色
    这篇文章主要介绍了pycharm怎么调背景颜色的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇pycharm怎么调背景颜色文章都会有所收获,下面我们一起来看看吧。pycharm调背景颜色的方法:首先点开左上角“f...
    99+
    2023-07-02
  • pycharm怎么调背景颜色为白色
    要将 pycharm 背景色更改为白色,请在“编辑器”设置中:选择“常规”主题。在“编辑器背景”中选择白色 (#ffffff)。单击“应用”以应用更改。 如何在 PyCharm 中将背...
    99+
    2024-04-18
    linux pycharm
  • android开发背景颜色怎么设置
    在Android开发中,可以通过以下方法来设置背景颜色:1. 在XML布局文件中设置背景颜色:在对应的View或Layout标签中添...
    99+
    2023-08-15
    android
  • Android怎么设置布局背景图
    在Android中,你可以通过以下几种方式来设置布局背景图:1. 使用XML布局文件:在你的XML布局文件中,可以通过在根布局中设置...
    99+
    2023-08-16
    android
  • css怎么实现li列表布局隔行背景颜色不同
    本文小编为大家详细介绍“ css怎么实现li列表布局隔行背景颜色不同”,内容详细,步骤清晰,细节处理妥当,希望这篇“ css怎么实现li列表布局隔行背景颜色不同”文章能帮助大家解决疑惑,下面跟着小编的思路慢...
    99+
    2024-04-02
  • Android展开与收起的背景颜色怎么设置
    要设置Android展开与收起的背景颜色,可以通过以下几种方式实现:1. 在布局文件中设置背景颜色:在需要展开与收起的布局文件中,可...
    99+
    2023-08-18
    Android
  • Android帧式布局怎么实现自动切换颜色
    本篇内容介绍了“Android帧式布局怎么实现自动切换颜色”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!效果:实现:activity_mai...
    99+
    2023-06-30
  • css怎么实现鼠标经过文字背景颜色或图片发生变化
    本篇内容介绍了“css怎么实现鼠标经过文字背景颜色或图片发生变化”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作