在通過(guò)簡(jiǎn)單的Android基礎(chǔ)講解之后有小伙伴們就來(lái)問(wèn)小編要怎么使用SeekBar,那么下面我們來(lái)講講有關(guān)于“在Android中怎么設(shè)置SeekBar禁止滑動(dòng)?”這個(gè)問(wèn)題的相關(guān)內(nèi)容分享!
由于項(xiàng)目需要,在關(guān)閉開(kāi)關(guān)的時(shí)候需要將頂部的調(diào)溫欄禁用,變?yōu)榛疑也豢牲c(diǎn)擊滑動(dòng),而開(kāi)的時(shí)候要啟用,變?yōu)辄S色且可點(diǎn)擊滑動(dòng)
為防止抓不住重點(diǎn),僅展示相關(guān)代碼
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){ //啟用狀態(tài) 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 { //禁用狀態(tài) 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); } } }
那么以上就是對(duì)于“在Android中怎么設(shè)置SeekBar禁止滑動(dòng)?”這個(gè)問(wèn)題的相關(guān)內(nèi)容分享,更多有關(guān)于Android這方面的相關(guān)內(nèi)容我們都可以在W3Cschool學(xué)習(xí)到更多的Android內(nèi)容和知識(shí)點(diǎn)。