Android: Using Switch Preference pre API level 14

后端 未结 5 1660
有刺的猬
有刺的猬 2020-12-13 19:04

Pre-API Level 14 there is no switch preference. If I use preferences.xml to create my preference screen is there some way to distinguish between the API levels? So having a

5条回答
  •  猫巷女王i
    2020-12-13 19:57

    you can use SwitchCompat:

    
    

    on setOnCheckedChangeListener:

    SwitchCompat switchCompat = (SwitchCompat)convertView.findViewById(R.id.switch_compat);
            switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        textView.setText("check");
                    } else {
                        textView.setText("unCheck");
                    }
                }
            });
    

    i hope help you.

提交回复
热议问题