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

55 阅读1分钟

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">

<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"

/>

<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"/>

<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">

<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"/>

<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"/>

<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">

<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">

<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"/>

自定义对话框实现类:

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) {

收集整理了一份《2024年最新物联网嵌入式全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升的朋友。 img img

如果你需要这些资料,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人

都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!