android 설정: inputType = "textPassword"실효 해결 방법

5644 단어 난치병
정상적으로 EditText를 사용하여 전면과 백엔드에서 setInputType(InputType.TYPE CLASSS TEXT | InputType.TYPE TEXT VARIATION PASSWORD)를 직접 설정합니다.네, 괜찮아요.
EditText가 사용자 정의 컨트롤에 포함되어 있고 다른 속성을 동시에 설정할 때 순서 문제에 주의해야 합니다. setInputType은 setSingleLine 뒤에 놓아야 합니다.android의 Bug가 될지 모르겠습니다.
다음은 본인이 쓴 컨트롤입니다. 기본값은 텍스트입니다. 입력 상자를 누르십시오.
import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.text.InputType;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sharera.capitalcircle.R;

/**
 *       
 * 
 * @author Administrator
 * 
 */
public class EditWithText extends LinearLayout {
	private TextView tv;
	private EditText et;
	private LinearLayout ll;
	private int inPutType;
	private Activity activity = new Activity();
	private Calendar c = Calendar.getInstance();

	//         
	private boolean isEditable = true;

	public void SetActivity(Activity activity) {
		this.activity = activity;
	}

	public EditWithText(Context context) {
		this(context, null);
	}

	public EditWithText(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater.from(context).inflate(R.layout.edit_with_text, this,
				true);
		tv = (TextView) findViewById(R.id.edit_with_text_t);
		et = (EditText) findViewById(R.id.edit_with_text_e);
		ll = (LinearLayout) findViewById(R.id.edit_with_text_layout);

		TypedArray a = context.obtainStyledAttributes(attrs,
				R.styleable.EditWithText);
		//       
		CharSequence text = a.getText(R.styleable.EditWithText_android_text);
		if (text != null)
			tv.setText(text);
		//      
		CharSequence hint = a.getText(R.styleable.EditWithText_android_hint);
		if (hint != null)
			tv.setHint(hint);
		//       
		int gravity = a.getInt(R.styleable.EditWithText_android_gravity, -100);
		if (gravity != -100) {
			ll.setGravity(gravity);
			tv.setGravity(gravity);
		}
		//      
		int maxLength = a
				.getInt(R.styleable.EditWithText_android_maxLength, 25);
		InputFilter[] filters = { new LengthFilter(maxLength) };
		et.setFilters(filters);
		//      
		String size = a.getString(R.styleable.EditWithText_android_textSize);
		if (size != null && size.length() > 0) {
			size = size.substring(0, size.length() - 2);
			et.setTextSize(TypedValue.COMPLEX_UNIT_SP, Float.valueOf(size));
			tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, Float.valueOf(size));
		}
		//       
		Boolean isMulti = a.getBoolean(
				R.styleable.EditWithText_android_singleLine, true);
		et.setSingleLine(isMulti);
		//       
		inPutType = a.getInt(R.styleable.EditWithText_android_inputType, -100);
		if (inPutType != -100) {
			et.setInputType(inPutType);
		}
		if (!isMulti) {
			tv.setGravity(Gravity.TOP);
			et.setGravity(Gravity.TOP);
			MarginLayoutParams tvMarginsParams = new MarginLayoutParams(
					tv.getLayoutParams());
			tvMarginsParams.setMargins(0, 15, 0, 13);
			tv.setLayoutParams(new LayoutParams(tvMarginsParams));
			MarginLayoutParams etMarginsParams = new MarginLayoutParams(
					et.getLayoutParams());
			etMarginsParams.setMargins(0, 10, 0, 13);
			et.setLayoutParams(new LayoutParams(etMarginsParams));
			InputFilter[] filters1 = { new LengthFilter(200) };
			et.setFilters(filters1);
		} else {
			tv.setGravity(Gravity.CENTER_VERTICAL);
			et.setGravity(Gravity.CENTER_VERTICAL);
		}
		a.recycle();

		tv.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (!isEditable)
					return;
				//   
				if (inPutType == 20) {
					// TODO Auto-generated method stub
					new DatePickerDialog(EditWithText.this.activity,
							new DatePickerDialog.OnDateSetListener() {

								@Override
								public void onDateSet(DatePicker view,
										int year, int monthOfYear,
										int dayOfMonth) {
									//     
									EditWithText.this.tv.setText(year + "-"
											+ monthOfYear + "-" + dayOfMonth);
									EditWithText.this.et.setText(year + "-"
											+ monthOfYear + "-" + dayOfMonth);
								}
							}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c
									.get(Calendar.DAY_OF_MONTH)).show();

				}

				else if (tv.getVisibility() == View.VISIBLE) {
					et.setText(tv.getText().toString());
					tv.setVisibility(View.GONE);
					et.setVisibility(View.VISIBLE);
					et.performClick();
					et.setFocusable(true);
					et.setFocusableInTouchMode(true);
					et.requestFocus();
					et.requestFocusFromTouch();
					InputMethodManager inputManager = (InputMethodManager) et
							.getContext().getSystemService(
									Context.INPUT_METHOD_SERVICE);
					inputManager.showSoftInput(et, 0);
				}
			}
		});
	}

	//    
	public void setText(String text) {
		tv.setText(text);

		//    EditText  
		et.setText(text);
	}

	//    
	public String getText() {
		return et.getText().toString().trim();
	}

	//         
	public boolean isEditable() {
		return isEditable;
	}

	//       
	public void setEditable(boolean isEditable) {
		this.isEditable = isEditable;
	}

	//     
	public void finishEdit() {
		tv.setVisibility(View.VISIBLE);
		et.setVisibility(View.GONE);
		// tv.setGravity(Gravity.RIGHT);
		setText(getText());
	}
}

좋은 웹페이지 즐겨찾기