android.widget.EditText#setEnabled ( )源码实例Demo

下面列出了android.widget.EditText#setEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: EditTextPreference.java
public EditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    
    mEditText = new EditText(context, attrs);
    
    // Give it an ID so it can be saved/restored
    mEditText.setId(com.android.internal.R.id.edit);
    
    /*
     * The preference framework and view framework both have an 'enabled'
     * attribute. Most likely, the 'enabled' specified in this XML is for
     * the preference framework, but it was also given to the view framework.
     * We reset the enabled state.
     */
    mEditText.setEnabled(true);
}
 
源代码2 项目: oversec   文件: ValidatedEditTextPreference.java
private void initialize(AttributeSet attrs) {
	// setup edit text
	mEditText = new EditText(getContext(), attrs);
	mEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
	mEditText.setEnabled(true);
	mEditText.setLayoutParams(new ViewGroup.LayoutParams(
			ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
	
	// setup layout for edit text
	int dip = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
			getContext().getResources().getDisplayMetrics()) + 0.5f);
	
	mEditTextlayout = new LinearLayout(getContext());
	mEditTextlayout.setLayoutParams(new ViewGroup.LayoutParams(
			ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
	mEditTextlayout.setPadding(dip, dip, dip, dip);
	mEditTextlayout.addView(mEditText);
}
 
源代码3 项目: PS4-Payload-Sender-Android   文件: Connection.java
public  void Connect(View view)
{
    final EditText ips = (EditText) findViewById(R.id.IPAddressTextBox);
    final EditText ports = (EditText) findViewById(R.id.PortTextBox);

    if (ips.getText().toString().equals("") || ports.getText().toString().equals("")) {
        new AlertDialog.Builder(this)
                .setTitle(R.string.error)
                .setMessage(R.string.enter_port_and_ip)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                })
                .show();
    }
    else
    {
        ip = ips.getText().toString();
        port = Integer.parseInt(ports.getText().toString());

        ips.setEnabled(false);
        ports.setEnabled(false);
        ConnectBtn.setEnabled(false);
        BrowseBtn.setEnabled(true);
    }
}
 
public void enDisBrokerAddressPort(boolean en,String brokerAddress, String brokerPort) {
    TextView t = (TextView)v.findViewById(R.id.cloud_broker_address_label);
    EditText e = (EditText)v.findViewById(R.id.cloud_broker_address);
    TextView tP = (TextView)v.findViewById(R.id.cloud_broker_port_label);
    EditText eP = (EditText)v.findViewById(R.id.cloud_broker_port);

    e.setEnabled(en);
    eP.setEnabled(en);
    e.setText(brokerAddress);
    eP.setText(brokerPort);
    if (en) {
        t.setAlpha(1.0f);
        e.setAlpha(1.0f);
        tP.setAlpha(1.0f);
        eP.setAlpha(1.0f);
    }
    else {
        t.setAlpha(0.4f);
        tP.setAlpha(0.4f);
        e.setAlpha(0.4f);
        eP.setAlpha(0.4f);
    }
}
 
public void enDisTopic(boolean en, String topic) {
    TextView t = (TextView)v.findViewById(R.id.cloud_publish_topic_label);
    EditText e = (EditText)v.findViewById(R.id.cloud_publish_topic);

    e.setEnabled(en);
    e.setText(topic);

    if (en) {
        t.setAlpha(1.0f);
        e.setAlpha(1.0f);
    }
    else {
        t.setAlpha(0.4f);
        e.setAlpha(0.4f);
    }
}
 
源代码6 项目: jterm-cswithandroid   文件: AnagramsActivity.java
public boolean defaultAction(View view) {
    TextView gameStatus = (TextView) findViewById(R.id.gameStatusView);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    EditText editText = (EditText) findViewById(R.id.editText);
    TextView resultView = (TextView) findViewById(R.id.resultView);
    if (currentWord == null) {
        currentWord = dictionary.pickGoodStarterWord();
        anagrams = dictionary.getAnagramsWithOneMoreLetter(currentWord);
        gameStatus.setText(Html.fromHtml(String.format(START_MESSAGE, currentWord.toUpperCase(), currentWord)));
        fab.setImageResource(android.R.drawable.ic_menu_help);
        fab.hide();
        resultView.setText("");
        editText.setText("");
        editText.setEnabled(true);
        editText.requestFocus();
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    } else {
        editText.setText(currentWord);
        editText.setEnabled(false);
        fab.setImageResource(android.R.drawable.ic_media_play);
        currentWord = null;
        resultView.append(TextUtils.join("\n", anagrams));
        gameStatus.append(" Hit 'Play' to start again");
    }
    return true;
}
 
源代码7 项目: xDrip   文件: NewSensorLocation.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_sensor_location);
    button = (Button)findViewById(R.id.saveSensorLocation);
    buttonCancel = (Button)findViewById(R.id.saveSensorLocationCancel);
    sensor_location_other = (EditText) findViewById(R.id.edit_sensor_location);
    sensor_location_other.setEnabled(false);
    DontAskAgain = (CheckBox)findViewById(R.id.sensorLocationDontAskAgain);
    radioGroup = (RadioGroup) findViewById(R.id.myRadioGroup);
    addListenerOnButton();

    locations = new LinkedList<Location>();

    locations.add(new Location("I don't wish to share", PRIVATE_ID));
    locations.add(new Location("Upper arm", 1));
    locations.add(new Location("Thigh", 2));
    locations.add(new Location("Belly (abdomen)", 3));
    locations.add(new Location("Lower back", 4));
    locations.add(new Location("Buttocks", 5));
    locations.add(new Location("Other", OTHER_ID));

    for(Location location : locations) {
        AddButton(location.location, location.location_id);
    }
    radioGroup.check(PRIVATE_ID);

}
 
源代码8 项目: geopaparazzi   文件: GDynamicEditTextView.java
private void addSingleEditText(Context context, LinearLayout mainLayout, String singleValue, boolean readonly, int type) {
    EditText editView = new EditText(context);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(15, 25, 15, 15);
    editView.setLayoutParams(params);
    editView.setText(singleValue);
    editView.setEnabled(!readonly);

    switch (type) {
        case 1:
            editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            break;
        case 2:
            editView.setInputType(InputType.TYPE_CLASS_PHONE);
            break;
        case 3:
            editView.setInputType(InputType.TYPE_CLASS_DATETIME);
            break;
        case 4:
            editView.setInputType(InputType.TYPE_CLASS_NUMBER);
            break;
        default:
            break;
    }

    mainLayout.addView(editView);
    editViewList.add(editView);
}
 
源代码9 项目: Conversations   文件: PinEntryWrapper.java
public void setEnabled(final boolean enabled) {
    for (EditText digit : digits) {
        digit.setEnabled(enabled);
        digit.setCursorVisible(enabled);
        digit.setFocusable(enabled);
        digit.setFocusableInTouchMode(enabled);
    }
    if (enabled) {
        final EditText last = digits.get(digits.size() - 1);
        if (last.getEditableText().length() > 0) {
            last.requestFocus();
        }
    }
}
 
public void enDisUsername (boolean enable,String username) {
    TextView t = (TextView)v.findViewById(R.id.cloud_username_label);
    EditText e = (EditText)v.findViewById(R.id.cloud_username);
    e.setEnabled(enable);
    e.setText(username);
    if (enable) {
        t.setAlpha(1.0f);
        e.setAlpha(1.0f);
    }
    else {
        t.setAlpha(0.4f);
        e.setAlpha(0.4f);
    }

}
 
源代码11 项目: xDrip-Experimental   文件: NewSensorLocation.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_sensor_location);
    button = (Button)findViewById(R.id.saveSensorLocation);
    buttonCancel = (Button)findViewById(R.id.saveSensorLocationCancel);
    sensor_location_other = (EditText) findViewById(R.id.edit_sensor_location);
    sensor_location_other.setEnabled(false);
    DontAskAgain = (CheckBox)findViewById(R.id.sensorLocationDontAskAgain);
    radioGroup = (RadioGroup) findViewById(R.id.myRadioGroup);
    addListenerOnButton();

    locations = new LinkedList<Location>();

    locations.add(new Location("I don't wish to share", PRIVATE_ID));
    locations.add(new Location("Upper arm", 1));
    locations.add(new Location("Thigh", 2));
    locations.add(new Location("Belly (abdomen)", 3));
    locations.add(new Location("Lower back", 4));
    locations.add(new Location("Buttocks", 5));
    locations.add(new Location("Other", OTHER_ID));

    for(Location location : locations) {
        AddButton(location.location, location.location_id);
    }
    radioGroup.check(PRIVATE_ID);

}
 
源代码12 项目: samba-documents-provider   文件: AuthActivity.java
private void prepareUI(String shareUri) {
  mSharePathEditText = (EditText) findViewById(R.id.share_path);
  mUsernameEditText = (EditText) findViewById(R.id.username);
  mDomainEditText = (EditText) findViewById(R.id.domain);
  mPasswordEditText = (EditText) findViewById(R.id.password);

  CheckBox passwordCheckbox = (CheckBox) findViewById(R.id.needs_password);
  mPinShareCheckbox = (CheckBox) findViewById(R.id.pin_share);

  mSharePathEditText.setText(shareUri);
  mSharePathEditText.setEnabled(false);

  passwordCheckbox.setVisibility(View.GONE);
  mPinShareCheckbox.setVisibility(View.VISIBLE);

  Button mLoginButton = (Button) findViewById(R.id.mount);
  mLoginButton.setText(getResources().getString(R.string.login));
  mLoginButton.setOnClickListener(mLoginListener);

  final Button cancel = (Button) findViewById(R.id.cancel);
  cancel.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      finish();
    }
  });
}
 
private void showVideoNotificationConnectDialog(String title, String roomName) {
    EditText roomEditText = new EditText(this);
    roomEditText.setText(roomName);
    // Use the default color instead of the disabled color
    int currentColor = roomEditText.getCurrentTextColor();
    roomEditText.setEnabled(false);
    roomEditText.setTextColor(currentColor);
    alertDialog = createConnectDialog(title,
            roomEditText,
            videoNotificationConnectClickListener(roomEditText),
            cancelConnectDialogClickListener(),
            this);
    alertDialog.show();
}
 
源代码14 项目: Cirrus_depricated   文件: AuthenticatorActivity.java
/**
 * 
 * @param savedInstanceState        Saved activity state, as in {{@link #onCreate(Bundle)}
 */
private void initAuthorizationPreFragment(Bundle savedInstanceState) {
    
    /// step 0 - get UI elements in layout
    mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check);
    mOAuthAuthEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_1);
    mOAuthTokenEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_2);
    mUsernameInput = (EditText) findViewById(R.id.account_username);
    mPasswordInput = (EditText) findViewById(R.id.account_password);
    mPasswordInput.setTypeface(mUsernameInput.getTypeface());
    mAuthStatusView = (TextView) findViewById(R.id.auth_status_text); 
    
    /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)
    String presetUserName = null;
    boolean isPasswordExposed = false;
    if (savedInstanceState == null) {
        if (mAccount != null) {
            presetUserName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));
        }
        
    } else {
        isPasswordExposed = savedInstanceState.getBoolean(KEY_PASSWORD_EXPOSED, false);
        mAuthStatusText = savedInstanceState.getInt(KEY_AUTH_STATUS_TEXT);
        mAuthStatusIcon = savedInstanceState.getInt(KEY_AUTH_STATUS_ICON);
        mAuthToken = savedInstanceState.getString(KEY_AUTH_TOKEN);
    }
    
    /// step 2 - set properties of UI elements (text, visibility, enabled...)
    mOAuth2Check.setChecked(
            AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType())
                .equals(mAuthTokenType));
    if (presetUserName != null) {
        mUsernameInput.setText(presetUserName);
    }
    if (mAction != ACTION_CREATE) {
        mUsernameInput.setEnabled(false);
        mUsernameInput.setFocusable(false);
    }
    mPasswordInput.setText(""); // clean password to avoid social hacking
    if (isPasswordExposed) {
        showPassword();
    }
    updateAuthenticationPreFragmentVisibility();
    showAuthStatus();
    mOkButton.setEnabled(mServerIsValid);

    
    /// step 3 - bind listeners
    // bindings for password input field
    mPasswordInput.setOnFocusChangeListener(this);
    mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
    mPasswordInput.setOnEditorActionListener(this);
    mPasswordInput.setOnTouchListener(new RightDrawableOnTouchListener() {
        @Override
        public boolean onDrawableTouch(final MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                AuthenticatorActivity.this.onViewPasswordClick();
            }
            return true;
        }
    });
    
}
 
源代码15 项目: ResearchStack   文件: PinCodeActivity.java
@Override
public void onDataAuth() {
    LogExt.e(getClass(), "onDataAuth()");
    storageAccessUnregister();

    // Show pincode layout
    PinCodeConfig config = StorageAccess.getInstance().getPinCodeConfig();

    int theme = ThemeUtils.getPassCodeTheme(this);
    pinCodeLayout = new PinCodeLayout(new ContextThemeWrapper(this, theme));
    pinCodeLayout.setBackgroundColor(Color.WHITE);

    int errorColor = getResources().getColor(R.color.rsb_error);

    TextView summary = (TextView) pinCodeLayout.findViewById(R.id.text);
    EditText pincode = (EditText) pinCodeLayout.findViewById(R.id.pincode);

    toggleKeyboardAction = enable -> {
        pincode.setEnabled(enable);
        pincode.setText("");
        pincode.requestFocus();
        if (enable) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(pincode, InputMethodManager.SHOW_FORCED);
        }
    };

    RxTextView.textChanges(pincode).map(CharSequence::toString).doOnNext(pin -> {
        if (summary.getCurrentTextColor() == errorColor) {
            summary.setTextColor(ThemeUtils.getTextColorPrimary(PinCodeActivity.this));
            pinCodeLayout.resetSummaryText();
        }
    }).filter(pin -> pin != null && pin.length() == config.getPinLength()).doOnNext(pin -> {
        pincode.setEnabled(false);
        pinCodeLayout.showProgress(true);
    }).flatMap(pin -> Observable.fromCallable(() -> {
        StorageAccess.getInstance().authenticate(PinCodeActivity.this, pin);
        return true;
    }).compose(ObservableUtils.applyDefault()).doOnError(throwable -> {
        toggleKeyboardAction.call(true);
        throwable.printStackTrace();
        summary.setText(R.string.rsb_pincode_enter_error);
        summary.setTextColor(errorColor);
        pinCodeLayout.showProgress(false);
    }).onErrorResumeNext(throwable1 -> {
        return Observable.empty();
    })).subscribe(success -> {
        if (!success) {
            toggleKeyboardAction.call(true);
        } else {
            getWindowManager().removeView(pinCodeLayout);
            pinCodeLayout = null;
            // authenticate() no longer calls notifyReady(), call this after auth
            requestStorageAccess();
        }
    });

    WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    getWindowManager().addView(pinCodeLayout, params);

    // Show keyboard, needs to be delayed, not sure why
    pinCodeLayout.postDelayed(() -> toggleKeyboardAction.call(true), 300);
}
 
源代码16 项目: Color-picker-library   文件: editsUtils.java
static void disableEditText(EditText editHEX, EditText someRGB, TextWatcher someRGBWatcher, TextWatcher hexWatcher) {
    someRGB.removeTextChangedListener(someRGBWatcher);
    someRGB.setEnabled(false);
    editHEX.removeTextChangedListener(hexWatcher);
    editHEX.setEnabled(false);
}
 
源代码17 项目: openwebnet-android   文件: IpcamActivity.java
private void enableEditText(EditText editText) {
    editText.setEnabled(true);
    editText.setFocusableInTouchMode(true);
}
 
源代码18 项目: geopaparazzi   文件: GEditTextView.java
/**
     * @param context               the context to use.
     * @param attrs                 attributes.
     * @param parentView            parent
     * @param label                 label
     * @param value                 value
     * @param type                  the text type.
     * @param lines                 the lines num.
     * @param constraintDescription constraints
     * @param readonly              if <code>false</code>, the item is disabled for editing.
     */
    public GEditTextView(Context context, AttributeSet attrs, LinearLayout parentView, String label, String value, int type,
                         int lines, String constraintDescription, boolean readonly) {
        super(context, attrs);

        LinearLayout textLayout = new LinearLayout(context);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(10, 10, 10, 10);
        textLayout.setLayoutParams(layoutParams);
        textLayout.setOrientation(LinearLayout.VERTICAL);
        parentView.addView(textLayout);

        TextView textView = new TextView(context);
        textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        textView.setPadding(2, 2, 2, 2);
        textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
        textView.setTextColor(Compat.getColor(context, R.color.formcolor));

        textLayout.addView(textView);

        editView = new EditText(context);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        params.setMargins(15, 25, 15, 15);
        editView.setLayoutParams(params);
//        editView.setPadding(15, 5, 15, 5);
        editView.setText(value);
        editView.setEnabled(!readonly);

        switch (type) {
            case 1:
                editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                break;
            case 2:
                editView.setInputType(InputType.TYPE_CLASS_PHONE);
                break;
            case 3:
                editView.setInputType(InputType.TYPE_CLASS_DATETIME);
                break;
            case 4:
                editView.setInputType(InputType.TYPE_CLASS_NUMBER);
                break;
            default:
                break;
        }

        if (lines > 0) {
            editView.setLines(lines);
            editView.setGravity(Gravity.TOP);
        }

        textLayout.addView(editView);
    }
 
源代码19 项目: biermacht   文件: AlertBuilder.java
public AlertDialog.Builder editTextFloatCheckBoxAlert(final TextView text, final TextView title, boolean checked, final BooleanCallback cb) {
  LayoutInflater factory = LayoutInflater.from(context);
  final LinearLayout alertView = (LinearLayout) factory.inflate(R.layout.alert_view_edit_text_float_with_check_box, null);
  final EditText editText = (EditText) alertView.findViewById(R.id.edit_text);
  final CheckBox checkBox = (CheckBox) alertView.findViewById(R.id.check_box);

  // Set text
  editText.setText(text.getText().toString());

  checkBox.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      cb.call(checkBox.isChecked());
      if (checkBox.isChecked()) {
        editText.setEnabled(false);
        editText.setClickable(false);
        editText.setFocusable(false);
        editText.setFocusableInTouchMode(false);
        editText.setText(text.getText().toString());
      }
      else {
        editText.setEnabled(true);
        editText.setClickable(true);
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
      }
    }
  });

  // Set the box to be checked or not.
  checkBox.setChecked(checked);

  // If checked initially, grey out edit text
  if (checked) {
    editText.setEnabled(false);
    editText.setClickable(false);
    editText.setFocusable(false);
    editText.setFocusableInTouchMode(false);
  }

  return new AlertDialog.Builder(context)
          .setTitle(title.getText().toString())
          .setView(alertView)
          .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
              text.setText(editText.getText().toString());
              callback.call();
              cb.call(checkBox.isChecked());
            }

          })

          .setNegativeButton(R.string.cancel, null);
}
 
源代码20 项目: Android-nRF-Toolbox   文件: UARTEditDialog.java
@NonNull
   @Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
	final LayoutInflater inflater = LayoutInflater.from(getActivity());

	// Read button configuration
	final Bundle args = requireArguments();
	final int index = args.getInt(ARG_INDEX);
	final String command = args.getString(ARG_COMMAND);
	final int eol = args.getInt(ARG_EOL);
	final int iconIndex = args.getInt(ARG_ICON_INDEX);
	final boolean active = true; // change to active by default
	activeIcon = iconIndex;

	// Create view
	final View view = inflater.inflate(R.layout.feature_uart_dialog_edit, null);
	final EditText field = this.field = view.findViewById(R.id.field);
	final GridView grid = view.findViewById(R.id.grid);
	final CheckBox checkBox = activeCheckBox = view.findViewById(R.id.active);
	checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
		field.setEnabled(isChecked);
		grid.setEnabled(isChecked);
		if (iconAdapter != null)
			iconAdapter.notifyDataSetChanged();
	});

	final RadioGroup eolGroup = this.eolGroup = view.findViewById(R.id.uart_eol);
	switch (Command.Eol.values()[eol]) {
		case CR_LF:
			eolGroup.check(R.id.uart_eol_cr_lf);
			break;
		case CR:
			eolGroup.check(R.id.uart_eol_cr);
			break;
		case LF:
		default:
			eolGroup.check(R.id.uart_eol_lf);
			break;
	}

	field.setText(command);
	field.setEnabled(active);
	checkBox.setChecked(active);
	grid.setOnItemClickListener(this);
	grid.setEnabled(active);
	grid.setAdapter(iconAdapter = new IconAdapter());

	// As we want to have some validation we can't user the DialogInterface.OnClickListener as it's always dismissing the dialog.
	final AlertDialog dialog = new AlertDialog.Builder(requireContext())
			.setCancelable(false)
			.setTitle(R.string.uart_edit_title)
			.setPositiveButton(R.string.ok, null)
			.setNegativeButton(R.string.cancel, null)
			.setView(view)
			.show();
	final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
	okButton.setOnClickListener(this);
	return dialog;
}