com.google.android.material.textfield.TextInputLayout Java Examples
The following examples show how to use
com.google.android.material.textfield.TextInputLayout.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HostsActivity.java From MHViewer with Apache License 2.0 | 7 votes |
protected void put(AlertDialog dialog) { TextView host = dialog.findViewById(R.id.host); TextView ip = dialog.findViewById(R.id.ip); String hostString = host.getText().toString().trim().toLowerCase(Locale.US); String ipString = ip.getText().toString().trim(); if (!Hosts.isValidHost(hostString)) { TextInputLayout hostInputLayout = dialog.findViewById(R.id.host_input_layout); hostInputLayout.setError(getContext().getString(R.string.invalid_host)); return; } if (!Hosts.isValidIp(ipString)) { TextInputLayout ipInputLayout = dialog.findViewById(R.id.ip_input_layout); ipInputLayout.setError(getContext().getString(R.string.invalid_ip)); return; } HostsActivity activity = (HostsActivity) dialog.getOwnerActivity(); activity.hosts.put(hostString, ipString); activity.notifyHostsChanges(); dialog.dismiss(); }
Example #2
Source File: TextInputLayoutMatchers.java From material-components-android with Apache License 2.0 | 6 votes |
/** * Returns a matcher that matches TextInputLayouts with non-empty content descriptions for the * end icon. */ public static Matcher<View> endIconHasContentDescription() { return new TypeSafeMatcher<View>(TextInputLayout.class) { @Override public void describeTo(Description description) { description.appendText( "TextInputLayout has non-empty content description" + "for end icon."); } @Override protected boolean matchesSafely(View view) { TextInputLayout item = (TextInputLayout) view; // Reach in and find the end icon since we don't have a public API to get a reference to it View endIcon = item.findViewById(R.id.text_input_end_icon); return !TextUtils.isEmpty(item.getEndIconContentDescription()) && !TextUtils.isEmpty(endIcon.getContentDescription()); } }; }
Example #3
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setHelperTextEnabled(final boolean enabled) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Enables/disables the helper"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setHelperTextEnabled(enabled); } }; }
Example #4
Source File: RangeDateSelector.java From material-components-android with Apache License 2.0 | 6 votes |
private void updateIfValidTextProposal( @NonNull TextInputLayout startTextInput, @NonNull TextInputLayout endTextInput, @NonNull OnSelectionChangedListener<Pair<Long, Long>> listener) { if (proposedTextStart == null || proposedTextEnd == null) { clearInvalidRange(startTextInput, endTextInput); listener.onIncompleteSelectionChanged(); return; } if (isValidRange(proposedTextStart, proposedTextEnd)) { selectedStartItem = proposedTextStart; selectedEndItem = proposedTextEnd; listener.onSelectionChanged(getSelection()); } else { setInvalidRange(startTextInput, endTextInput); listener.onIncompleteSelectionChanged(); } }
Example #5
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setErrorIconOnClickListener(final OnClickListener onClickListener) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Set error icon OnClickListener"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setErrorIconOnClickListener(onClickListener); } }; }
Example #6
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setErrorTextAppearance(final int resId) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Sets the error text appearance"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setErrorTextAppearance(resId); } }; }
Example #7
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setError(final CharSequence errorText) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Sets the error"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setError(errorText); } }; }
Example #8
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setHelperText(final CharSequence helperText) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Sets the helper"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setHelperText(helperText); } }; }
Example #9
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setStartIconOnLongClickListener( final OnLongClickListener onLongClickListener) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Set a long click listener for the start icon"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setStartIconOnLongClickListener(onLongClickListener); } }; }
Example #10
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
/** Long clicks end or start icon. */ public static ViewAction longClickIcon(final boolean isEndIcon) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return ViewMatchers.isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Long clicks the end or start icon"; } @Override public void perform(UiController uiController, View view) { TextInputLayout item = (TextInputLayout) view; // Reach in and find the icon view since we don't have a public API to get a reference to it CheckableImageButton iconView = item.findViewById(isEndIcon ? R.id.text_input_end_icon : R.id.text_input_start_icon); iconView.performLongClick(); } }; }
Example #11
Source File: EditProfileActivity.java From Aria2App with GNU General Public License v3.0 | 6 votes |
private void handleInvalidFieldException(@NonNull InvalidFieldException ex) { if (ex.where == Where.ACTIVITY) { TextInputLayout field = findViewById(ex.fieldId); field.clearFocus(); field.setErrorEnabled(true); field.setError(getString(ex.reasonRes)); return; } if (ex.pos == -1) return; showConditionAt(ex.pos); FieldErrorFragmentWithState fragment = (FieldErrorFragmentWithState) pagerAdapter.get(ex.where); pager.setCurrentItem(ex.where.pagerPos(), true); fragment.onFieldError(ex.fieldId, getString(ex.reasonRes)); }
Example #12
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setHint(final String hint) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Sets the hint/label text"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setHint(hint); } }; }
Example #13
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
/** Sets the transformation method. */ public static ViewAction setTransformationMethod( final TransformationMethod transformationMethod) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return ViewMatchers.isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Sets the transformation method"; } @Override public void perform(UiController uiController, View view) { TextInputLayout item = (TextInputLayout) view; item.getEditText().setTransformationMethod(transformationMethod); } }; }
Example #14
Source File: DynamicInputUtils.java From dynamic-support with Apache License 2.0 | 6 votes |
/** * Tint the {@link TextInputLayout} by changing its label and focus colors according to the * supplied color. * * @param textInputLayout The text input layout to be colorized. * @param color The color to be used. */ public static void setColor(@NonNull TextInputLayout textInputLayout, @ColorInt int color) { try { Field fFocusedTextColor = TextInputLayout.class.getDeclaredField("focusedTextColor"); fFocusedTextColor.setAccessible(true); fFocusedTextColor.set(textInputLayout, ColorStateList.valueOf(color)); Method mUpdateLabelState = TextInputLayout.class.getDeclaredMethod( "updateLabelState", boolean.class, boolean.class); mUpdateLabelState.setAccessible(true); mUpdateLabelState.invoke(textInputLayout, false, true); } catch (Exception e) { e.printStackTrace(); } if (textInputLayout.getEditText() != null) { setColor(textInputLayout.getEditText(), textInputLayout.getBoxBackgroundColor(), color); textInputLayout.setHintTextColor(textInputLayout.getEditText().getHintTextColors()); } }
Example #15
Source File: DynamicTextInputEditText.java From dynamic-support with Apache License 2.0 | 6 votes |
@Override public void setColor() { if (mColor != WidgetDefaults.ADS_COLOR_UNKNOWN) { if (isBackgroundAware() && mContrastWithColor != WidgetDefaults.ADS_COLOR_UNKNOWN) { mColor = DynamicColorUtils.getContrastColor(mColor, mContrastWithColor); } post(new Runnable() { @Override public void run() { TextInputLayout parent = getParentTextInputLayout(); if (parent != null) { DynamicInputUtils.setColor(DynamicTextInputEditText.this, parent.getBoxBackgroundColor(), mColor); } } }); } }
Example #16
Source File: TextInputLayoutMatchers.java From material-components-android with Apache License 2.0 | 6 votes |
/** Returns a matcher that matches TextInputLayouts with non-displayed end icons. */ public static Matcher<View> doesNotShowEndIcon() { return new TypeSafeMatcher<View>(TextInputLayout.class) { @Override public void describeTo(Description description) { description.appendText("TextInputLayout doesn't show end icon."); } @Override protected boolean matchesSafely(View item) { // Reach in and find the end icon since we don't have a public API // to get a reference to it View endIcon = item.findViewById(R.id.text_input_end_icon); return endIcon.getVisibility() != View.VISIBLE; } }; }
Example #17
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setStartIconOnClickListener(final OnClickListener onClickListener) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Set a click listener for the start icon"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setStartIconOnClickListener(onClickListener); } }; }
Example #18
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setEndIconMode(final int endIconMode) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Set end icon mode"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setEndIconMode(endIconMode); } }; }
Example #19
Source File: ReportBugsHelper.java From candybar with Apache License 2.0 | 6 votes |
public static void prepareReportBugs(@NonNull Context context) { MaterialDialog.Builder builder = new MaterialDialog.Builder(context); builder.customView(R.layout.dialog_report_bugs, true); builder.typeface( TypefaceHelper.getMedium(context), TypefaceHelper.getRegular(context)); builder.positiveText(R.string.report_bugs_send); builder.negativeText(R.string.close); MaterialDialog dialog = builder.build(); EditText editText = (EditText) dialog.findViewById(R.id.input_desc); TextInputLayout inputLayout = (TextInputLayout) dialog.findViewById(R.id.input_layout); dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(view -> { if (editText.getText().length() > 0) { inputLayout.setErrorEnabled(false); ReportBugsTask.start(context, editText.getText().toString(), AsyncTask.THREAD_POOL_EXECUTOR); dialog.dismiss(); return; } inputLayout.setError(context.getResources().getString(R.string.report_bugs_desc_empty)); }); dialog.show(); }
Example #20
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setCounterEnabled(final boolean enabled) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Sets the counter enabled"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setCounterEnabled(enabled); } }; }
Example #21
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setTypeface(final Typeface typeface) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Sets the typeface"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setTypeface(typeface); } }; }
Example #22
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setStartIconContentDescription(final CharSequence contentDesc) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Set a content description for the start icon"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setStartIconContentDescription(contentDesc); } }; }
Example #23
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setHelperTextTextAppearance(final int resId) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Sets the helper text appearance"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setHelperTextTextAppearance(resId); } }; }
Example #24
Source File: TextLabelDetailsFragment.java From science-journal with Apache License 2.0 | 6 votes |
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) { setHasOptionsMenu(true); noteTextLayout = (TextInputLayout) inflater.inflate(R.layout.text_label_details_fragment, container, false); noteText = noteTextLayout.findViewById(R.id.note_text); noteText.setText(originalLabel.getTextLabelValue().getText()); noteText.post(() -> noteText.setSelection(noteText.getText().toString().length())); RxTextView.afterTextChangeEvents(noteText) .subscribe( events -> { verifyInput(noteText.getText().toString()); }); // TODO: Transition return noteTextLayout; }
Example #25
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setCustomEndIconContent() { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Set custom end icon content"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setEndIconDrawable(new ColorDrawable(Color.BLUE)); layout.setEndIconContentDescription(R.string.textinput_custom_end_icon); } }; }
Example #26
Source File: AddCameraActivity.java From evercam-android with GNU Affero General Public License v3.0 | 6 votes |
private void populateDefaultAuth() { if (mSelectedModel != null) { String defaultUsername = mSelectedModel.getDefaultUsername(); String defaultPassword = mSelectedModel.getDefaultPassword(); TextInputLayout usernameInputLayout = (TextInputLayout) findViewById(R.id.input_layout_cam_username); TextInputLayout passwordInputLayout = (TextInputLayout) findViewById(R.id.input_layout_cam_password); usernameInputLayout.setErrorEnabled(true); passwordInputLayout.setErrorEnabled(true); if (!defaultUsername.isEmpty()) { usernameInputLayout.setError(getString(R.string.default_colon) + defaultUsername); } else { usernameInputLayout.setErrorEnabled(false); } if (!defaultPassword.isEmpty()) { passwordInputLayout.setError(getString(R.string.default_colon) + defaultPassword); } else { passwordInputLayout.setErrorEnabled(false); } } }
Example #27
Source File: RangeDateSelectorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void textInputFormatError() { View root = rangeDateSelector.onCreateTextInputView( LayoutInflater.from(context), null, null, new CalendarConstraints.Builder().build(), new OnSelectionChangedListener<Pair<Long, Long>>() { @Override public void onSelectionChanged(Pair<Long, Long> selection) {} }); TextInputLayout startTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_start); TextInputLayout endTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_end); startTextInput.getEditText().setText("22/22/2010", BufferType.EDITABLE); endTextInput.getEditText().setText("555-555-5555", BufferType.EDITABLE); assertThat(startTextInput.getError(), notNullValue()); assertThat(endTextInput.getError(), notNullValue()); }
Example #28
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
/** Clicks end or start icon. */ public static ViewAction clickIcon(final boolean isEndIcon) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return ViewMatchers.isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Clicks the end or start icon"; } @Override public void perform(UiController uiController, View view) { TextInputLayout item = (TextInputLayout) view; // Reach in and find the icon view since we don't have a public API to get a reference to it CheckableImageButton iconView = item.findViewById(isEndIcon ? R.id.text_input_end_icon : R.id.text_input_start_icon); iconView.performClick(); } }; }
Example #29
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
public static ViewAction setEndIconOnClickListener(final OnClickListener onClickListener) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Set end icon OnClickListener"; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setEndIconOnClickListener(onClickListener); } }; }
Example #30
Source File: TextInputLayoutActions.java From material-components-android with Apache License 2.0 | 6 votes |
/** * Sets the text field's stroke width. * * @param strokeWidth the value to use for the text field box's stroke * @return the action of setting the box stroke width on a {@link TextInputLayout} */ public static ViewAction setBoxStrokeWidth(final int strokeWidth) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(TextInputLayout.class); } @Override public String getDescription() { return "Sets the box's stroke width."; } @Override public void perform(UiController uiController, View view) { TextInputLayout layout = (TextInputLayout) view; layout.setBoxStrokeWidth(strokeWidth); } }; }