android.support.design.widget.TextInputLayout类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(188)

本文整理了Java中android.support.design.widget.TextInputLayout类的一些代码示例,展示了TextInputLayout类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextInputLayout类的具体详情如下:
包路径:android.support.design.widget.TextInputLayout
类名称:TextInputLayout

TextInputLayout介绍

暂无

代码示例

代码示例来源:origin: hidroh/materialistic

private boolean validate() {
  mTitleLayout.setErrorEnabled(false);
  mContentLayout.setErrorEnabled(false);
  if (mTitleEditText.length() == 0) {
    mTitleLayout.setError(getString(R.string.title_required));
  }
  if (mContentEditText.length() == 0) {
    mContentLayout.setError(getString(R.string.url_text_required));
  }
  return mTitleEditText.length() > 0 && mContentEditText.length() > 0;
}

代码示例来源:origin: north2016/T-MVP

private void doAction() {
  String name = mViewBinding.tlName.getEditText().getText().toString();
  String pass = mViewBinding.tlPass.getEditText().getText().toString();
  String msg = TextUtils.isEmpty(name) ? "用户名不能为空!" : TextUtils.isEmpty(pass) ? "密码不能为空!" : "";
  if (!TextUtils.isEmpty(msg)) showMsg(msg);
  else if (isLogin) mPresenter.login(name, pass);
  else mPresenter.sign(name, pass);
}

代码示例来源:origin: seven332/EhViewer

@SuppressLint("InflateParams")
public EditTextDialogBuilder(Context context, String text, String hint) {
  super(context);
  View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_edittext_builder, null);
  setView(view);
  mTextInputLayout = (TextInputLayout) view;
  mEditText = (EditText) view.findViewById(R.id.edit_text);
  mEditText.setText(text);
  mEditText.setSelection(mEditText.getText().length());
  mEditText.setOnEditorActionListener(this);
  mTextInputLayout.setHint(hint);
}

代码示例来源:origin: seven332/EhViewer

public void setError(CharSequence error) {
  mTextInputLayout.setError(error);
}

代码示例来源:origin: GitLqr/MaterialDesignDemo

@Override
  public void afterTextChanged(Editable s) {
    if (mTextInputLayout.getEditText().getText().toString().trim().length() > 6) {
      mTextInputLayout.setErrorEnabled(true);
      mTextInputLayout.setError(mErrorTip);
    } else {
      mTextInputLayout.setErrorEnabled(false);
    }
  }
}

代码示例来源:origin: bparmentier/WiFiKeyShare

@Override
  public void afterTextChanged(Editable editable) {
    wifiPasswordDialog.getButton(DialogInterface.BUTTON_POSITIVE)
        .setEnabled(editable.length() >= 5);
    if (wifiPasswordWrapper.getError() != null) {
      try {
        if (WifiNetwork.isValidKeyLength(wifiNetwork.getAuthType(),
            editable.toString())) {
          wifiPasswordWrapper.setError(null);
        }
      } catch (final WifiException e) {
        switch (e.getErrorCode()) {
          case WifiException.WEP_KEY_LENGTH_ERROR:
            wifiPasswordWrapper.setError(getString(R.string.error_wep_password_length));
            break;
          case WifiException.WPA_KEY_LENGTH_ERROR:
            wifiPasswordWrapper.setError(getString(R.string.error_wpa_password_length));
            break;
          default:
            wifiPasswordWrapper.setError(e.getMessage());
            break;
        }
      }
    }
  }
});

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreate(Bundle state) {
 super.onCreate(state);
 setContentView(R.layout.main);
 til=(TextInputLayout)findViewById(R.id.til);
 til.setErrorEnabled(true);
}

代码示例来源:origin: 18Gray/ProCamera

@Override
protected void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.aty_mine);
  ButterKnife.bind(this);
  context = this;
  et_name = til_name_mine.getEditText();
  til_name_mine.setHint("请输入姓名:");
  et_password = til_password_mine.getEditText();
  til_password_mine.setHint("请输入密码:");
  snackBarView = LayoutInflater.from(context).inflate(R.layout.view_snackbar, null);
  btn_mine.setOnClickListener(new View.OnClickListener()
  {
    @Override
    public void onClick(View view)
    {
      showSnackBar();
    }
  });
}

代码示例来源:origin: jbruchanov/AnUitor

@Override
  protected HashMap<String, Object> fillValues(View v, HashMap<String, Object> data, HashMap<String, Object> parentData) {
    super.fillValues(v, data, parentData);

    TextInputLayout view = (TextInputLayout) v;

    data.put("Error", view.getError());
    data.put("Hint", view.getHint());
    data.put("PasswordVisibilityToggleContentDescription", view.getPasswordVisibilityToggleContentDescription());
    data.put("PasswordVisibilityToggleDrawable:", view.getPasswordVisibilityToggleDrawable());
    data.put("Typeface:", view.getTypeface());
    data.put("IsCounterEnabled", view.isCounterEnabled());
    data.put("IsErrorEnabled", view.isErrorEnabled());
    data.put("IsHintAnimationEnabled", view.isHintAnimationEnabled());
    data.put("IsHintEnabled", view.isHintEnabled());
    data.put("IsPasswordVisibilityToggleEnabled", view.isPasswordVisibilityToggleEnabled());

    return data;
  }
}

代码示例来源:origin: GitLqr/MaterialDesignDemo

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_text_input_layout);
  mTextInputLayout = (TextInputLayout) findViewById(R.id.textInputLayout);
  //开启计数
  mTextInputLayout.setCounterEnabled(true);
  mTextInputLayout.setCounterMaxLength(6);
  //定义错误提示
  mTextInputLayout.getEditText().addTextChangedListener(new MyTextWatch(mTextInputLayout, "长度不能超过6个字符"));
}

代码示例来源:origin: Sea-n/Android-TG-Bot

textInputLayout.setHint(name);
ViewGroup.LayoutParams layoutParams = textInputLayout.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
textInputLayout.setLayoutParams(layoutParams);
  type |= TYPE_FILE;
final InstantComplete autoCompleteTextView = new InstantComplete(textInputLayout.getContext());
  textInputLayout.addView(checkBox);
  iListView.add(checkBox);
} else {
  textInputLayout.addView(autoCompleteTextView);
  iListView.add(autoCompleteTextView);

代码示例来源:origin: apptentive/apptentive-android

nameLayout.setVisibility(GONE);
} else {
  nameLayout.setVisibility(VISIBLE);
  nameLayout.setHint(whoCard.getNameHint());
emailLayout.setHint(whoCard.getEmailHint());
emailEditText.setText(Apptentive.getPersonEmail());
if (Util.isEmailValid(emailEditText.getText().toString().trim())) {

代码示例来源:origin: apptentive/apptentive-android

answerTextInputLayout.setHint(hint);
  answerTextInputLayout.setContentDescription(hint);
  answer.setContentDescription(hint);
  answerTextInputLayout.setGravity(Gravity.TOP | Gravity.START);
  answer.setGravity(Gravity.TOP | Gravity.START);
  answer.setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
  answer.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
} else {
  answerTextInputLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
  answer.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
  answer.setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);
  answerTextInputLayout.setLabelFor(R.id.answer_text);

代码示例来源:origin: square/assertj-android

public TextInputLayoutAssert hasError(CharSequence error) {
  isNotNull();
  CharSequence actualError = actual.getError();

  assertThat(actualError) //
    .overridingErrorMessage("Expected error '<%s>' but was '<%s>'.", error, actualError) //
    .isEqualTo(error);
  return this;
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

public void showMe(View v) {
  EditText urlField=(EditText)findViewById(R.id.url);
  String url=urlField.getText().toString();

  if (Patterns.WEB_URL.matcher(url).matches()) {
   startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
  }
  else {
   til.setError(getString(R.string.til_error));
  }
 }
}

代码示例来源:origin: henrymorgen/android-advanced-light

private void login() {
 String username=tl_username.getEditText().getText().toString();
 String password=tl_password.getEditText().getText().toString();
 if(!validateUserName(username)) {
   tl_username.setErrorEnabled(true);
   tl_username.setError("请输入正确的邮箱地址");
 }else if(!validatePassword(password)) {
   tl_password.setErrorEnabled(true);
   tl_password.setError("密码字数过少");
 } else {
   tl_username.setErrorEnabled(false);
   tl_password.setErrorEnabled(false);
   Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show();
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreate(Bundle state) {
 super.onCreate(state);
 setContentView(R.layout.main);
 til=(TextInputLayout)findViewById(R.id.til);
 til.setErrorEnabled(true);
}

代码示例来源:origin: journey-M/AutoMissingMessage

private void initView() {
  msgweQueeView = (MessagQuenView) findViewById(R.id.msgQuenView);
  thumbContainer = (RelativeLayout) findViewById(R.id.thumbContainer);
  txtLayout = (TextInputLayout) findViewById(R.id.txtLayout);
  mEdMsg = txtLayout.getEditText();
  txtLayout.setHint("输入要发送的消息内容");
  btnSendMsg = (Button) findViewById(R.id.btn_sendmsg);
  btnThumbs = (Button) findViewById(R.id.btn_thumb);
  btnJoin = (Button) findViewById(R.id.btn_join);
  btnThumbs.setOnClickListener(this);
  btnSendMsg.setOnClickListener(this);
  btnJoin.setOnClickListener(this);
  Toast.makeText(this, "a", Toast.LENGTH_SHORT).show();
}

代码示例来源:origin: hidroh/materialistic

@Test
public void testEmptyInput() {
  activity.findViewById(R.id.feedback_button).performClick();
  assertNotNull(((TextInputLayout) activity.findViewById(R.id.textinput_title)).getError());
  assertNotNull(((TextInputLayout) activity.findViewById(R.id.textinput_body)).getError());
  verify(feedbackClient, never()).send(any(), any(), any(FeedbackClient.Callback.class));
  assertThat(activity).isNotFinishing();
  controller.pause().stop().destroy();
}

代码示例来源:origin: hidroh/materialistic

private boolean validate() {
  mUsernameLayout.setErrorEnabled(false);
  mPasswordLayout.setErrorEnabled(false);
  if (mUsernameEditText.length() == 0) {
    mUsernameLayout.setError(getString(R.string.username_required));
  }
  if (mPasswordEditText.length() == 0) {
    mPasswordLayout.setError(getString(R.string.password_required));
  }
  return mUsernameEditText.length() > 0 && mPasswordEditText.length() > 0;
}

相关文章