效果图:

自定义对话框布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<!--自定义对话框,线性布局水平方向--> <!--第一部分标题栏-->
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#257CFF"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="设置阈值"
android:textColor="@android:color/white"
android:textSize="18sp"/> <!--设置温度阈值-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="温度阈值设置:"
android:textColor="#6C6C6C"/> <!--设置阈值-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal"> <LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"> <TextView
android:id="@+id/tv_tempValue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="30"/> <TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="℃"
/>
</LinearLayout> <SeekBar
android:id="@+id/sb_temp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:max="60"
android:progress="30"/>
</LinearLayout> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="数值范围 0-60℃"
android:textColor="#6C6C6C"/> <!--分割线-->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#cccccc"></View>
<!--设置湿度阈值-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="湿度阈值设置:"
android:textColor="#6C6C6C"/> <!--设置阈值-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal"> <LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"> <TextView
android:id="@+id/tv_humiValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="30"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="%RH"
/>
</LinearLayout> <SeekBar
android:id="@+id/sb_humi"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:max="100"
android:progress="30"/>
</LinearLayout> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="数值范围 0-100%RH"
android:textColor="#6C6C6C"/>
<!--分割线-->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#cccccc"></View>
<!--设置光照阈值-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="光照阈值设置:"
android:textColor="#6C6C6C"/> <!--设置阈值-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal"> <LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"> <TextView
android:id="@+id/tv_lightValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="3000"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lx"/>
</LinearLayout> <SeekBar
android:id="@+id/sb_light"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:max="10000"
android:progress="3000"/>
</LinearLayout> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="数值范围 0-10000Lx"
android:textColor="#6C6C6C"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#cccccc"></View>
<!--确定,取消按钮-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <Button
android:id="@+id/btn_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/white"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="确定"
android:textColor="#257CFF"/>
<!--分割线-->
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#cccccc"></View>
<Button
android:id="@+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/white"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="取消"
android:textColor="#257CFF"/>
</LinearLayout>
</LinearLayout>

自定义对话框实现类:

package com.newland.project3_3;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView; /**
* 设置阈值对话框
*/
public class SettingThresholdDialog extends Dialog { private TextView tvTempValue,tvHumiValue,tvLightValue;
private Button btnCancel;
private Button btnConfirm;
private SeekBar sbTemp,sbHumi,sbLight; public SettingThresholdDialog(@NonNull Context context) {
super(context,R.style.Dialog);
//关联布局文件
this.setContentView(R.layout.dialog_setting_threshold);
//初始化组件
initView();
addListener();
} private void initView() {
sbTemp = findViewById(R.id.sb_temp);
sbHumi = findViewById(R.id.sb_humi);
sbLight = findViewById(R.id.sb_light);
tvTempValue = findViewById(R.id.tv_tempValue);
tvHumiValue = findViewById(R.id.tv_humiValue);
tvLightValue = findViewById(R.id.tv_lightValue);
btnCancel = findViewById(R.id.btn_cancel);
btnConfirm = findViewById(R.id.btn_confirm);
} private void addListener() {
//温度SeekBar状态改变监听
sbTemp.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//SeekBar进度显示到TextView上
tvTempValue.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) { }
});
//湿度SeekBar状态改变监听
sbHumi.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//SeekBar进度显示到TextView上
tvHumiValue.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) { }
});
//光照SeekBar状态改变监听
sbLight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//SeekBar进度显示到TextView上
tvLightValue.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) { }
});
//设置确定点击事件
btnConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//对话框消失
SettingThresholdDialog.this.dismiss();
}
});
//设置取消点击事件
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//对话框消失
SettingThresholdDialog.this.dismiss();
}
});
}
}

在主类中创建对话框并显示:

package com.newland.project3_3;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//创建对话框并显示
SettingThresholdDialog dialog = new SettingThresholdDialog(this);
dialog.show();
}
}

Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面的更多相关文章

  1. Android物联网应用程序开发(智慧园区)—— 图片预览界面

    效果图: 实现步骤: 1.首先在 build.gradle 文件中引入 RecycleView implementation 'com.android.support:recyclerview-v7: ...

  2. Android物联网应用程序开发(智慧城市)—— 环境状态值范围设置界面开发

    效果图: 代码: 布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...

  3. Android物联网应用程序开发(智慧园区)—— 园区监控系统界面

    效果图: 布局代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...

  4. Android物联网应用程序开发(智慧园区)—— 登录界面开发

    效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

  5. Android物联网应用程序开发(智慧城市)—— 查询购物信息界面开发

    效果: 布局代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xm ...

  6. Android物联网应用程序开发(智慧城市)—— 用户注册界面开发

    效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: ...

  7. Android物联网应用程序开发(智慧城市)—— 摄像头监控界面开发

    效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: ...

  8. Android物联网应用程序开发(智慧城市)—— 火焰监控界面开发

    效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: ...

  9. Android物联网应用程序开发(智慧城市)—— 购物信息的存储界面开发

    效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

随机推荐

  1. 一道题目学ES6 API,合并对象id相同的两个数组对象

    var arr2=[{id:1,name:'23'}] var arr1=[{id:1,car:'car2'}] const combined = arr2.reduce((acc, cur) =&g ...

  2. git pull、git fetch、git merge、git rebase的区别

    一.git pull与git fetch区别 1.两者的区别       两者都是更新远程仓库代码到本地. git fetch相当于是从远程获取最新版本到本地,不会自动merge. 只是将远程仓库最新 ...

  3. Spring.DM版HelloWorld

    本文主要描述使用Spring.DM2.0,创建OSGi的HelloWorld演示程序,理解Spring.DM的OSGi框架实现机制.   环境描述: 项目 版本 Eclipse 3.7.x JDK 1 ...

  4. Java易错小结

    String 相关运算 String使用是注意是否初始化,未初始化的全部为null.不要轻易使用 string.isEmpty()等,首先确保string非空. 推荐使用StringUtils.isN ...

  5. I/O流之文件流

    1.文件操作类 File 1.public File(String pathname)//给定一个要操作文件的完整路径 2.public File(File parent,String child)/ ...

  6. 【力扣】82. 删除排序链表中的重复元素 II

    存在一个按升序排列的链表,给你这个链表的头节点 head ,请你删除链表中所有存在数字重复情况的节点,只保留原始链表中 没有重复出现 的数字. 返回同样按升序排列的结果链表. 示例 1: 输入:hea ...

  7. 华为云函数中使用云数据库的JavaScript SDK基础入门

    背景介绍 使用云数据库Server端的SDK,此处我以华为提供的官方Demo为例,他们的Demo也已经开源放在了GitHub上,大家需要的可以自行下载. https://github.com/AppG ...

  8. Jenkins安全加固

    1.jenkins未授权访问 描述 jenkins不当配置可导致未授权访问管理控制台,可以通过脚本命令行执行系统命令.通过该漏洞,可以后台管理服务,通过脚本命令行功能执行系统命令,如反弹shell,w ...

  9. cmd窗口连接mongodb服务端

    1----->配置环境变量,将mongodb\bin目录配置到path 2----->打开cmd窗口,进入到bin目录,测试mongodb服务端是否在运行:net start mongod ...

  10. live2d

    原文来自https://www.fghrsh.net/post/123.html Live2D 看板娘 v1.4 / Demo 3 - 内置 waifu-tips.json (博客园等网站引用推荐) ...