|
|
@@ -0,0 +1,85 @@
|
|
|
+package com.mgtech.base_library.custom;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.content.res.TypedArray;
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
+import android.util.AttributeSet;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
+
|
|
|
+import com.mgtech.base_library.R;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ProjectName: BaseLibrary
|
|
|
+ * @Package: com.tennor.base_library.custom
|
|
|
+ * @ClassName: PhoneAreaCodeEditView
|
|
|
+ * @Description: 带手机区号edittext
|
|
|
+ * @Author: 牛松涛
|
|
|
+ * @CreateDate: 2020/4/20 14:52
|
|
|
+ * @UpdateUser: 更新者:
|
|
|
+ * @UpdateDate: 2020/4/20 14:52
|
|
|
+ * @UpdateRemark: 更新说明:
|
|
|
+ * @Version: 1.0
|
|
|
+ */
|
|
|
+public class PhoneAreaCodeEditView extends ConstraintLayout {
|
|
|
+ private TextView areaCodeText;
|
|
|
+ private EditText phoneEdit;
|
|
|
+ private View lineView;
|
|
|
+
|
|
|
+ public PhoneAreaCodeEditView(Context context) {
|
|
|
+ super(context);
|
|
|
+ }
|
|
|
+
|
|
|
+ public PhoneAreaCodeEditView(Context context, AttributeSet attrs) {
|
|
|
+ super(context, attrs);
|
|
|
+ initView(context);
|
|
|
+ setView(context, attrs);
|
|
|
+ }
|
|
|
+
|
|
|
+ public PhoneAreaCodeEditView(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
+ super(context, attrs, defStyleAttr);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initView(Context context){
|
|
|
+ LayoutInflater.from(context).inflate(R.layout.layout_phone_area_code_edit,this);
|
|
|
+ areaCodeText = findViewById(R.id.area_code);
|
|
|
+ phoneEdit = findViewById(R.id.area_phone_num);
|
|
|
+ lineView = findViewById(R.id.area_line);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setView(Context context, AttributeSet attr){
|
|
|
+ TypedArray typedArray = context.obtainStyledAttributes(attr, R.styleable.PhoneAreaCodeEditView);
|
|
|
+ phoneEdit.setHint(typedArray.getString(R.styleable.PhoneAreaCodeEditView_phone_edit_area_hint_text));
|
|
|
+ phoneEdit.setBackgroundResource(typedArray.getResourceId(R.styleable.PhoneAreaCodeEditView_phone_edit_area_input_bg
|
|
|
+ ,0));
|
|
|
+ areaCodeText.setText(typedArray.getString(R.styleable.PhoneAreaCodeEditView_phone_edit_area_code));
|
|
|
+ Drawable drawable = typedArray.getDrawable(R.styleable.PhoneAreaCodeEditView_phone_edit_area_flag_icon);
|
|
|
+ if (drawable != null)
|
|
|
+ areaCodeText.setCompoundDrawables(getDrawable(drawable),null,null,null);
|
|
|
+ lineView.setVisibility(typedArray.getBoolean(R.styleable.PhoneAreaCodeEditView_phone_edit_area_line_show,true) ? VISIBLE : GONE);
|
|
|
+ typedArray.recycle();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setPhoneEditText(String phone){
|
|
|
+ phoneEdit.setText(phone);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String getPhoneEdit(){
|
|
|
+ return phoneEdit.getText().toString().trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ public EditText getInputText(){
|
|
|
+ return phoneEdit;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Drawable getDrawable(Drawable drawable){
|
|
|
+ drawable.setBounds(0,0,drawable.getMinimumWidth(),drawable.getMinimumHeight());
|
|
|
+ return drawable;
|
|
|
+ }
|
|
|
+}
|