Java Code Examples for android.widget.TextView#setHint()
The following examples show how to use
android.widget.TextView#setHint() .
These examples are extracted from open source projects.
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 Project: green_android File: TwoFactorActivity.java License: GNU General Public License v3.0 | 6 votes |
private TextView setupDetailsView(final int inputType, final String hint) { setView(R.layout.activity_two_factor_3_provide_details, R.id.activity_two_factor_3_provide_details); final TextView detailsText = UI.find(this, R.id.details); detailsText.setInputType(inputType); detailsText.setHint(hint); final InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); // Show the keyboard; this workaround is needed due to Android bugs detailsText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { detailsText.postDelayed(() -> { detailsText.requestFocus(); imm.showSoftInput(detailsText, 0); }, 100); } } }); return detailsText; }
Example 2
Source Project: Android-WYSIWYG-Editor File: ImageExtensions.java License: Apache License 2.0 | 6 votes |
private void hideInputHint(int index) { View view = editorCore.getParentView().getChildAt(index); EditorType type = editorCore.getControlType(view); if (type != EditorType.INPUT) return; String hint = editorCore.getPlaceHolder(); if (index > 0) { View prevView = editorCore.getParentView().getChildAt(index - 1); EditorType prevType = editorCore.getControlType(prevView); if (prevType == EditorType.INPUT) hint = null; } TextView tv = (TextView) view; tv.setHint(hint); }
Example 3
Source Project: youqu_master File: UiUtils.java License: Apache License 2.0 | 5 votes |
/** * 设置hint大小 * * @param size * @param v * @param res */ public static void setViewHintSize(Context context, int size, TextView v, int res) { SpannableString ss = new SpannableString(getResources(context).getString( res)); // 新建一个属性对象,设置文字的大小 AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true); // 附加属性到文本 ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失 }
Example 4
Source Project: Android-Hint-Spinner File: HintAdapter.java License: MIT License | 5 votes |
private View getDefaultView(ViewGroup parent) { View view = inflateDefaultLayout(parent); TextView textView = (TextView) view.findViewById(android.R.id.text1); textView.setText(""); textView.setHint(hintResource); return view; }
Example 5
Source Project: Aurora File: UiUtils.java License: Apache License 2.0 | 5 votes |
/** * 设置hint大小 * * @param size * @param v * @param res */ public static void setViewHintSize(Context context, int size, TextView v, int res) { SpannableString ss = new SpannableString(getResources(context).getString( res)); // 新建一个属性对象,设置文字的大小 AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true); // 附加属性到文本 ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失 }
Example 6
Source Project: Aurora File: ArmsUtils.java License: Apache License 2.0 | 5 votes |
/** * 设置hint大小 * * @param size * @param v * @param res */ public static void setViewHintSize(Context context, int size, TextView v, int res) { SpannableString ss = new SpannableString(getResources(context).getString( res)); // 新建一个属性对象,设置文字的大小 AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true); // 附加属性到文本 ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失 }
Example 7
Source Project: SimpleDialogFragments File: SpinnerViewHolder.java License: Apache License 2.0 | 5 votes |
@Override public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) { View view = super.getDropDownView(position, convertView, parent); if (position == emptyIndex) { TextView label = (TextView) view.findViewById(android.R.id.text1); label.setText(""); label.setHint(getItem(position)); } return view; }
Example 8
Source Project: SimpleDialogFragments File: HintViewHolder.java License: Apache License 2.0 | 5 votes |
@Override protected void setUpView(View view, Context context, Bundle savedInstanceState, final SimpleFormDialog.DialogActions actions) { TextView label = (TextView) view.findViewById(R.id.label); label.setHint(field.getText(context)); }
Example 9
Source Project: MVVMArms File: UiUtils.java License: Apache License 2.0 | 5 votes |
/** * 设置hint大小 * * @param size * @param v * @param res */ public static void setViewHintSize(Context context, int size, TextView v, int res) { SpannableString ss = new SpannableString(getResources(context).getString( res)); // 新建一个属性对象,设置文字的大小 AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true); // 附加属性到文本 ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint,一定要进行转换,否则属性会消失 v.setHint(new SpannedString(ss)); }
Example 10
Source Project: android-test File: ViewMatchersTest.java License: Apache License 2.0 | 5 votes |
@Test public void withHintResourceId_charSequenceTest() { TextView textView = new TextView(context); String expectedText = context.getResources().getString(R.string.something); Spannable textSpan = Spannable.Factory.getInstance().newSpannable(expectedText); textSpan.setSpan(new ForegroundColorSpan(Color.RED), 0, expectedText.length() - 1, 0); textView.setHint(textSpan); assertTrue(withHint(R.string.something).matches(textView)); assertFalse(withHint(R.string.other_string).matches(textView)); }
Example 11
Source Project: Android-WYSIWYG-Editor File: ImageExtensions.java License: Apache License 2.0 | 5 votes |
private void showNextInputHint(int index) { View view = editorCore.getParentView().getChildAt(index); EditorType type = editorCore.getControlType(view); if (type != EditorType.INPUT) return; TextView tv = (TextView) view; tv.setHint(editorCore.getPlaceHolder()); Linkify.addLinks(tv,Linkify.ALL); }
Example 12
Source Project: SimpleDialogFragments File: SpinnerViewHolder.java License: Apache License 2.0 | 5 votes |
@NonNull @Override public View getView(int position, View convertView, @NonNull ViewGroup parent) { View view = super.getView(position, convertView, parent); if (position == emptyIndex) { TextView label = (TextView) view.findViewById(android.R.id.text1); label.setText(""); label.setHint(getItem(position)); } return view; }
Example 13
Source Project: SimpleDialogFragments File: SpinnerViewHolder.java License: Apache License 2.0 | 5 votes |
@Override public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) { View view = super.getDropDownView(position, convertView, parent); if (position == emptyIndex) { TextView label = (TextView) view.findViewById(android.R.id.text1); label.setText(""); label.setHint(getItem(position)); } return view; }
Example 14
Source Project: android-test File: ViewMatchersTest.java License: Apache License 2.0 | 5 votes |
@Test public void withHintNullTest() { TextView textView = new TextView(context); textView.setHint(null); assertTrue(withHint(nullValue(String.class)).matches(textView)); assertFalse(withHint("").matches(textView)); }
Example 15
Source Project: MVPArms File: ArmsUtils.java License: Apache License 2.0 | 5 votes |
/** * 设置hint大小 * * @param size * @param v * @param res */ public static void setViewHintSize(Context context, int size, TextView v, int res) { SpannableString ss = new SpannableString(getResources(context).getString( res)); // 新建一个属性对象,设置文字的大小 AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true); // 附加属性到文本 ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失 }
Example 16
Source Project: AndroidBase File: UiUtils.java License: Apache License 2.0 | 5 votes |
/** * 设置hint大小 * * @param size * @param v * @param res */ public static void setViewHintSize(int size, TextView v, int res) { SpannableString ss = new SpannableString(getResources().getString( res)); // 新建一个属性对象,设置文字的大小 AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true); // 附加属性到文本 ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失 }
Example 17
Source Project: MVPAndroidBootstrap File: SearchViewUtil.java License: Apache License 2.0 | 5 votes |
/** * Sets the searchview's hint icon and text. * * @param searchView * @param drawableResource * @param hintText */ public static void setSearchHintIcon(SearchView searchView, int drawableResource, String hintText) { try { // Accessing the SearchAutoComplete int queryTextViewId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); View autoComplete = searchView.findViewById(queryTextViewId); //Class<?> clazz = Class.forName("android.widget.SearchView$SearchAutoComplete"); TextView searchBox = (TextView) searchView.findViewById(R.id.search_src_text); SpannableStringBuilder stopHint = new SpannableStringBuilder(" "); stopHint.append(hintText); // Add the icon as an spannable Drawable searchIcon = searchView.getContext().getResources().getDrawable(drawableResource); Float rawTextSize = searchBox.getTextSize(); int textSize = (int) (rawTextSize * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Set the new hint text searchBox.setHint(stopHint); //searchBox.setTextColor(Color.WHITE); searchBox.setHintTextColor(Color.LTGRAY); } catch (Exception e) { Log.e("SearchView", e.getMessage(), e); } }
Example 18
Source Project: RxAndroidBootstrap File: SearchViewUtil.java License: Apache License 2.0 | 5 votes |
/** * Sets the searchview's hint icon and text. * * @param searchView * @param drawableResource * @param hintText */ public static void setSearchHintIcon(SearchView searchView, int drawableResource, String hintText) { try { // Accessing the SearchAutoComplete int queryTextViewId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); View autoComplete = searchView.findViewById(queryTextViewId); //Class<?> clazz = Class.forName("android.widget.SearchView$SearchAutoComplete"); TextView searchBox = (TextView) searchView.findViewById(R.id.search_src_text); SpannableStringBuilder stopHint = new SpannableStringBuilder(" "); stopHint.append(hintText); // Add the icon as an spannable Drawable searchIcon = searchView.getContext().getResources().getDrawable(drawableResource); Float rawTextSize = searchBox.getTextSize(); int textSize = (int) (rawTextSize * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Set the new hint text searchBox.setHint(stopHint); //searchBox.setTextColor(Color.WHITE); searchBox.setHintTextColor(Color.LTGRAY); } catch (Exception e) { Log.e("SearchView", e.getMessage(), e); } }
Example 19
Source Project: ResearchStack File: DateQuestionBody.java License: Apache License 2.0 | 4 votes |
@Override public View getBodyView(int viewType, LayoutInflater inflater, ViewGroup parent) { View view = inflater.inflate(R.layout.rsb_item_date_view, parent, false); TextView title = (TextView) view.findViewById(R.id.label); if (viewType == VIEW_TYPE_COMPACT) { title.setText(step.getTitle()); } else { title.setVisibility(View.GONE); } TextView textView = (TextView) view.findViewById(R.id.value); textView.setSingleLine(true); if (step.getPlaceholder() != null) { textView.setHint(step.getPlaceholder()); } else { if (format.getStyle() == AnswerFormat.DateAnswerStyle.Date) { textView.setHint(R.string.rsb_hint_step_body_date); } else if (format.getStyle() == AnswerFormat.DateAnswerStyle.TimeOfDay) { textView.setHint(R.string.rsb_hint_step_body_time); } else if (format.getStyle() == AnswerFormat.DateAnswerStyle.DateAndTime) { textView.setHint(R.string.rsb_hint_step_body_datetime); } } if (result.getResult() != null) { textView.setText(createFormattedResult()); } textView.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { showDialog(textView); } }); textView.setOnClickListener(v -> { if (v.isFocused()) { showDialog(textView); } }); Resources res = parent.getResources(); LinearLayout.MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.leftMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_left); layoutParams.rightMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_right); view.setLayoutParams(layoutParams); return view; }
Example 20
Source Project: Android-Hint-Spinner File: HintAdapter.java License: MIT License | 3 votes |
/** * Hook method to set a custom view. * * Provides a default implementation using the simple spinner dropdown item. * * @param position Position selected * @param convertView View * @param parent Parent view group */ protected View getCustomView(int position, View convertView, ViewGroup parent) { View view = inflateDefaultLayout(parent); Object item = getItem(position); TextView textView = (TextView) view.findViewById(android.R.id.text1); textView.setText(item.toString()); textView.setHint(""); return view; }