Android SeekBar禁止滑动 Android SeekBar实现禁止滑动
酥脆 人气:0想了解Android SeekBar实现禁止滑动的相关内容吗,酥脆在本文为您仔细讲解Android SeekBar禁止滑动的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,SeekBar,禁止滑动,下面大家一起来学习吧。
由于项目需要,在关闭开关的时候需要将顶部的调温栏禁用,变为灰色且不可点击滑动,而开的时候要启用,变为黄色且可点击滑动
为防止抓不住重点,仅展示相关代码
public class DeviceControlActivity extends Activity implements View.OnClickListener,SeekBar.OnSeekBarChangeListener{ private SeekBar mSeekBar; private TextView mLowTempTextView; private TextView mMiddleTempTextView; private TextView mHighTempTextView; private Button mSwitchButton; private int mSwitchButtonStatus =0; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.device_control_layout); initView(); intiData(); initEvent(); } private void initView(){ mSeekBar=findViewById(R.id.id_seek_bar); } private void initEvent(){ mSeekBar.setOnSeekBarChangeListener(this); setSeekBarClickable(0);//先禁用seekBar } @Override public void onClick(View view) { switch (view.getId()){ case R.id.id_device_control_switch_button: if (mSwitchButtonStatus ==1){ mSwitchButton.setBackgroundResource(R.drawable.switch_button_off_img); mSwitchButtonStatus =0; sendAt("AT+IO1=L"); setSeekBarClickable(mSwitchButtonStatus);//禁用 }else { mSwitchButton.setBackgroundResource(R.drawable.switch_button_on_img); mSwitchButtonStatus =1; sendAt("AT+IO1=H"); setSeekBarClickable(mSwitchButtonStatus);//启用 } break; } } private void setSeekBarClickable(int i){ if (i==1){ //启用状态 mSeekBar.setClickable(true); mSeekBar.setEnabled(true); mSeekBar.setSelected(true); mSeekBar.setFocusable(true); Drawable drawable=getResources().getDrawable(R.drawable.yellow_mid_img_40); mSeekBar.setThumb(drawable); mSeekBar.setProgress(50); }else { //禁用状态 mSeekBar.setClickable(false); mSeekBar.setEnabled(false); mSeekBar.setSelected(false); mSeekBar.setFocusable(false); Drawable drawable=getResources().getDrawable(R.drawable.seek_bar_grey_img_40); mSeekBar.setThumb(drawable); mSeekBar.setProgress(50); } } }
加载全部内容