Java Code Examples for android.widget.TextView#setHint()

The following examples show how to use android.widget.TextView#setHint() . 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: TwoFactorActivity.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
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 File: ImageExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 6 votes vote down vote up
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 File: HintAdapter.java    From Android-Hint-Spinner with MIT License 5 votes vote down vote up
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 4
Source File: SearchViewUtil.java    From RxAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
/**
     * 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 5
Source File: SearchViewUtil.java    From MVPAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
/**
     * 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 6
Source File: UiUtils.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 设置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 7
Source File: ArmsUtils.java    From MVPArms with Apache License 2.0 5 votes vote down vote up
/**
 * 设置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 8
Source File: ViewMatchersTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
public void withHintNullTest() {
  TextView textView = new TextView(context);
  textView.setHint(null);
  assertTrue(withHint(nullValue(String.class)).matches(textView));
  assertFalse(withHint("").matches(textView));
}
 
Example 9
Source File: SpinnerViewHolder.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: SpinnerViewHolder.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: ImageExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 5 votes vote down vote up
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 File: ViewMatchersTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: UiUtils.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
/**
 * 设置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 14
Source File: HintViewHolder.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@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 15
Source File: SpinnerViewHolder.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@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 16
Source File: ArmsUtils.java    From Aurora with Apache License 2.0 5 votes vote down vote up
/**
 * 设置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 17
Source File: UiUtils.java    From Aurora with Apache License 2.0 5 votes vote down vote up
/**
 * 设置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 18
Source File: UiUtils.java    From youqu_master with Apache License 2.0 5 votes vote down vote up
/**
 * 设置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 19
Source File: DateQuestionBody.java    From ResearchStack with Apache License 2.0 4 votes vote down vote up
@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 File: HintAdapter.java    From Android-Hint-Spinner with MIT License 3 votes vote down vote up
/**
 * 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;
}