package safeluck.drive.evaluation.fragment.rulefragments.cview; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.CheckBox; import android.widget.LinearLayout; import android.widget.TextView; import safeluck.drive.evaluation.R; /** * DriveJudge * Created by lzw on 2020/9/24. 10:25:00 * 邮箱:632393724@qq.com * All Rights Saved! Chongqing AnYun Tech co. LTD */ public class TextCheckBox extends LinearLayout { private CheckBox checkBox; public TextCheckBox(Context context) { this(context,null); } public TextCheckBox(Context context, AttributeSet attrs) { this(context, attrs,0); } public TextCheckBox(Context context, AttributeSet attrs, int defStyleAttr) { this(context, attrs, defStyleAttr,0); } public TextCheckBox(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); initView(context,attrs); } private void initView(Context context, AttributeSet attrs) { View view = LayoutInflater.from(context).inflate(R.layout.layout_text_checkbox,this,true); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TextCheckBox_attr_tvcheck); String string = typedArray.getString(R.styleable.TextCheckBox_attr_tvcheck_txt_des_check); boolean aBoolean = typedArray.getBoolean(R.styleable.TextCheckBox_attr_tvcheck_check_not, false); TextView text = view.findViewById(R.id.tv_checkbox); text.setText(string); checkBox = view.findViewById(R.id.check_setting); checkBox.setChecked(aBoolean); } }