Java Code Examples for android.widget.EditText#setBackgroundResource()

The following examples show how to use android.widget.EditText#setBackgroundResource() . 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: EditSpinner.java    From EditSpinner with Apache License 2.0 6 votes vote down vote up
private void initView(AttributeSet attrs) {
    LayoutInflater.from(mContext).inflate(R.layout.edit_spinner, this);
    editText = (EditText) findViewById(R.id.edit_sipnner_edit);
    mRightIv = (ImageView) findViewById(R.id.edit_spinner_expand);
    mRightImageTopView = findViewById(R.id.edit_spinner_expand_above);
    mRightImageTopView.setOnClickListener(this);
    mRightImageTopView.setClickable(false);
    mRightIv.setOnClickListener(this);
    mRightIv.setRotation(90);
    editText.addTextChangedListener(this);
    TypedArray tArray = mContext.obtainStyledAttributes(attrs,
            R.styleable.EditSpinner);
    editText.setHint(tArray.getString(R.styleable.EditSpinner_hint));
    int imageId = tArray.getResourceId(R.styleable.EditSpinner_rightImage, 0);
    if (imageId != 0) {
        mRightIv.setImageResource(imageId);
    }
    int bg = tArray.getResourceId(R.styleable.EditSpinner_Background, 0);
    if (bg != 0) {
        editText.setBackgroundResource(bg);
    }
    maxLine = tArray.getInt(R.styleable.EditSpinner_maxLine, 1);
    editText.setMaxLines(maxLine);
    tArray.recycle();
}
 
Example 2
Source File: QueryRequestActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private void buildPromptEntry(LinearLayout promptsLayout, String promptId,
                              DisplayUnit displayUnit, boolean isLastPrompt) {
    Hashtable<String, String> userAnswers =
            remoteQuerySessionManager.getUserAnswers();
    promptsLayout.addView(createPromptMedia(displayUnit));

    EditText promptEditText = new EditText(this);
    if (userAnswers.containsKey(promptId)) {
        promptEditText.setText(userAnswers.get(promptId));
    }
    promptEditText.setBackgroundResource(R.drawable.login_edit_text);
    // needed to allow 'done' and 'next' keyboard action
    promptEditText.setSingleLine();

    if (isLastPrompt) {
        promptEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    } else {
        // replace 'done' on keyboard with 'next'
        promptEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    }
    promptsLayout.addView(promptEditText);
    promptsBoxes.put(promptId, promptEditText);
}
 
Example 3
Source File: TextEntryElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected View createView(Context c) {
    et = new EditText(c);
    et.setBackgroundResource(R.drawable.oval);
    et.setTextColor(c.getResources()
            .getColorStateList(R.color.primary_text_holo_light));
    et.setText(answer);
    et.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
    if (!NumericType.NONE.equals(numericType)) {
        KeyListener listener = getKeyListenerForType(numericType);
        if (listener != null)
            et.setKeyListener(listener);
    } else {
        et.setRawInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
                TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    }
    return encapsulateQuestion(c, et);
}
 
Example 4
Source File: MyWebView.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
public void init(Context context) {
    // This lets the layout editor display the view.
    if (isInEditMode()) return;

    mContext = context;

    mFocusDistraction = new EditText(context);
    mFocusDistraction.setBackgroundResource(android.R.color.transparent);
    this.addView(mFocusDistraction);
    mFocusDistraction.getLayoutParams().width = 1;
    mFocusDistraction.getLayoutParams().height = 1;
}
 
Example 5
Source File: MyWebView.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
public void init(Context context) {
    // This lets the layout editor display the view.
    if (isInEditMode()) return;

    mContext = context;

    mFocusDistraction = new EditText(context);
    mFocusDistraction.setBackgroundResource(android.R.color.transparent);
    this.addView(mFocusDistraction);
    mFocusDistraction.getLayoutParams().width = 1;
    mFocusDistraction.getLayoutParams().height = 1;
}
 
Example 6
Source File: Pinview.java    From Pinview with MIT License 5 votes vote down vote up
/**
 * Takes care of styling the editText passed in the param.
 * tag is the index of the editText.
 *
 * @param styleEditText
 * @param tag
 */
private void generateOneEditText(EditText styleEditText, String tag) {
    params.setMargins(mSplitWidth / 2, mSplitWidth / 2, mSplitWidth / 2, mSplitWidth / 2);
    filters[0] = new InputFilter.LengthFilter(1);
    styleEditText.setFilters(filters);
    styleEditText.setLayoutParams(params);
    styleEditText.setGravity(Gravity.CENTER);
    styleEditText.setCursorVisible(mCursorVisible);

    if (!mCursorVisible) {
        styleEditText.setClickable(false);
        styleEditText.setHint(mHint);

        styleEditText.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                // When back space is pressed it goes to delete mode and when u click on an edit Text it should get out of the delete mode
                mDelPressed = false;
                return false;
            }
        });
    }
    styleEditText.setBackgroundResource(mPinBackground);
    styleEditText.setPadding(0, 0, 0, 0);
    styleEditText.setTag(tag);
    styleEditText.setInputType(getKeyboardInputType());
    styleEditText.addTextChangedListener(this);
    styleEditText.setOnFocusChangeListener(this);
    styleEditText.setOnKeyListener(this);
}
 
Example 7
Source File: EditCommandAliasActivity.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
private static void setEditTextDisabled(EditText editText) {
    editText.setInputType(InputType.TYPE_NULL);
    editText.setTextIsSelectable(true);
    editText.setKeyListener(null);

    editText.setBackgroundResource(R.drawable.edit_text_readonly);
    int color = StyledAttributesHelper.getColor(editText.getContext(), android.R.attr.textColorSecondary, 0);
    ViewCompat.setBackgroundTintList(editText, ColorStateList.valueOf(color));
    ((ViewGroup) editText.getParent()).setAddStatesFromChildren(false);
}
 
Example 8
Source File: PinViewBaseHelper.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set a PinBox with all attributes
 *
 * @param editText to set attributes
 */
private void setStylePinBox(EditText editText) {
    editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(mNumberCharacters)});

    if (mMaskPassword) {
        editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    }
    else{
        editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
    }

    if (mNativePinBox) {
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            //noinspection deprecation
            editText.setBackgroundDrawable(new EditText(getContext()).getBackground());
        } else {
            editText.setBackground(new EditText(getContext()).getBackground());
        }
    } else {
        editText.setBackgroundResource(mCustomDrawablePinBox);
    }

    if (mColorTextPinBoxes != PinViewSettings.DEFAULT_TEXT_COLOR_PIN_BOX) {
        editText.setTextColor(mColorTextPinBoxes);
    }
    editText.setTextSize(PinViewUtils.convertPixelToDp(getContext(), mTextSizePinBoxes));
}
 
Example 9
Source File: PinViewBaseHelper.java    From PinView with Apache License 2.0 5 votes vote down vote up
/**
 * Set a PinBox with all attributes
 *
 * @param editText to set attributes
 */
private void setStylePinBox(EditText editText) {
    editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(mNumberCharacters)});

    if (mMaskPassword) {
        editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    }
    else{
        editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
    }

    if (mNativePinBox) {
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            //noinspection deprecation
            editText.setBackgroundDrawable(new EditText(getContext()).getBackground());
        } else {
            editText.setBackground(new EditText(getContext()).getBackground());
        }
    } else {
        editText.setBackgroundResource(mCustomDrawablePinBox);
    }

    if (mColorTextPinBoxes != PinViewSettings.DEFAULT_TEXT_COLOR_PIN_BOX) {
        editText.setTextColor(mColorTextPinBoxes);
    }
    editText.setTextSize(PinViewUtils.convertPixelToDp(getContext(), mTextSizePinBoxes));
}
 
Example 10
Source File: LyricsViewFragment.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
private void startEditTagsMode() {
    ImageButton editButton = getActivity().findViewById(R.id.edit_tags_btn);
    editButton.setImageResource(R.drawable.ic_edit_anim);
    ((Animatable) editButton.getDrawable()).start();

    ((DrawerLayout) ((MainActivity) getActivity()).drawer).setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    mRefreshLayout.setEnabled(false);
    getActivity().findViewById(R.id.refresh_fab).setEnabled(false);
    ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).hide();
    ((Toolbar) getActivity().findViewById(R.id.toolbar)).getMenu().clear();

    ViewSwitcher viewSwitcher = getActivity().findViewById(R.id.switcher);
    EditText songTV = getActivity().findViewById(R.id.song);
    TextView artistTV = getActivity().findViewById(R.id.artist);

    EditText newLyrics = getActivity().findViewById(R.id.edit_lyrics);
    newLyrics.setTypeface(LyricsTextFactory.FontCache.get("light", getActivity()));
    newLyrics.setText(Html.fromHtml(TextUtils.isEmpty(mLyrics.getText()) ? "" : mLyrics.getText()), TextView.BufferType.EDITABLE);

    viewSwitcher.setVisibility(View.GONE);
    newLyrics.setVisibility(View.VISIBLE);

    songTV.setInputType(InputType.TYPE_CLASS_TEXT);
    artistTV.setInputType(InputType.TYPE_CLASS_TEXT);
    songTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
    artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material);


    if (songTV.requestFocus()) {
        InputMethodManager imm = (InputMethodManager)
                getActivity().getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.SHOW_IMPLICIT);
    }
}
 
Example 11
Source File: Pinview.java    From Pinview with MIT License 4 votes vote down vote up
public void setPinBackgroundRes(@DrawableRes int res) {
    this.mPinBackground = res;
    for (EditText editText : editTextList)
        editText.setBackgroundResource(res);
}
 
Example 12
Source File: PlusMinusNum.java    From K-Sonic with MIT License 4 votes vote down vote up
private void initView() {
    setOrientation(LinearLayout.HORIZONTAL);

    // =========@center Layout
    centerLL = new LinearLayout(getContext());
    editText = new EditText(getContext());
    editText.setInputType(InputType.TYPE_CLASS_NUMBER);//TYPE_NULL
    editText.setText(String.valueOf(num));
    editText.setTextColor(0xff229EBF);
    editText.setBackgroundResource(R.drawable.num_edit);
    editText.setPadding(0, 0, 0, 0);
    editText.setGravity(Gravity.CENTER);
    editText.setMinimumWidth(ediTextMinimumWidth);
    LayoutParams ediTextLP = new LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    editText.setLayoutParams(ediTextLP);

    LayoutParams centerLP = new LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    centerLP.gravity = Gravity.CENTER;
    centerLL.setLayoutParams(centerLP);
    centerLL.setFocusable(true);
    centerLL.setFocusableInTouchMode(true);


    // =========@left/right Layout
    minusButton = new Button(getContext());
    minusButton.setText(minusButtonText);
    minusButton.setTextColor(0xff666666);
    minusButton.setTag(minusButtonText);
    minusButton.setBackgroundResource(R.drawable.num_minus);
    minusButton.setPadding(0, 0, 0, 0);

    plusButton = new Button(getContext());
    plusButton.setText(plusButtonText);
    plusButton.setTextColor(0xff666666);
    plusButton.setTag(plusButtonText);
    plusButton.setBackgroundResource(R.drawable.num_plus);
    plusButton.setPadding(0, 0, 0, 0);

    LayoutParams buttonLP = new LayoutParams(
            buttonWidth,
            LinearLayout.LayoutParams.MATCH_PARENT);
    plusButton.setLayoutParams(buttonLP);
    minusButton.setLayoutParams(buttonLP);
}
 
Example 13
Source File: Detail.java    From faveo-helpdesk-android-app with Open Software License 3.0 4 votes vote down vote up
private void setErrorState(EditText editText, TextView textViewError, String error) {
    editText.setBackgroundResource(R.drawable.edittext_error_state);
    editText.setPadding(0, paddingTop, 0, paddingBottom);
    textViewError.setText(error);
}
 
Example 14
Source File: CreateTicket.java    From faveo-helpdesk-android-app with Open Software License 3.0 4 votes vote down vote up
private void setErrorState(EditText editText, TextView textViewError, String error) {
    editText.setBackgroundResource(R.drawable.edittext_error_state);
    editText.setPadding(0, paddingTop, 0, paddingBottom);
    textViewError.setText(error);
}