android.widget.EditText#setMaxLines ( )源码实例Demo

下面列出了android.widget.EditText#setMaxLines ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TelePlus-Android   文件: EditTextSettingsCell.java
public EditTextSettingsCell(Context context) {
    super(context);

    textView = new EditText(context);
    textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    textView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    textView.setBackgroundDrawable(null);
    textView.setPadding(0, 0, 0, 0);
    textView.setInputType(textView.getInputType() |EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);
    addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 17, 0, 17, 0));
}
 
源代码2 项目: TelePlus-Android   文件: EditTextSettingsCell.java
public EditTextSettingsCell(Context context) {
    super(context);

    textView = new EditText(context);
    textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    textView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    textView.setBackgroundDrawable(null);
    textView.setPadding(0, 0, 0, 0);
    textView.setInputType(textView.getInputType() |EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);
    addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 17, 0, 17, 0));
}
 
源代码3 项目: ankihelper   文件: PopupActivity.java
private void setupEditNoteDialog() {
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PopupActivity.this);
        LayoutInflater inflater = PopupActivity.this.getLayoutInflater();
        final View dialogView = inflater.inflate(R.layout.dialog_edit_note, null);
        dialogBuilder.setView(dialogView);

        final EditText edt = (EditText) dialogView.findViewById(R.id.edit_note);
        edt.setHorizontallyScrolling(false);
        edt.setMaxLines(4);
        edt.setText(mNoteEditedByUser);
        edt.setSelection(mNoteEditedByUser.length());
        dialogBuilder.setTitle(R.string.dialog_note);
        //dialogBuilder.setMessage("输入笔记");
        dialogBuilder.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                mNoteEditedByUser = edt.getText().toString();
            }
        });
//                        dialogBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                            public void onClick(DialogInterface dialog, int whichButton) {
//                                //pass
//                            }
//                        });
        AlertDialog b = dialogBuilder.create();
        b.show();
    }
 
源代码4 项目: EditSpinner   文件: EditSpinner.java
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();
}
 
源代码5 项目: superXingPostCard   文件: EditCardActivity.java
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_editcard);

        WindowManager.LayoutParams params = getWindow().getAttributes();
//        params.x = -20;
//        params.y = -10;

//        params.height = 100;
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        this.getWindow().setAttributes(params);

        editcardEt = (EditText) findViewById(R.id.editcard_et);
        editcardEt.setText(getIntent().getStringExtra("words"));
        editcardEt.setMaxLines(8);
        editcardBt = (Button) findViewById(R.id.editcard_bt);
        editcardBt.setOnClickListener(this);

    }
 
源代码6 项目: hash-checker   文件: HashCalculatorFragment.java
private void validateMultilineFields(
        @NonNull EditText editText,
        int lines,
        boolean singleLine
) {
    editText.setSingleLine(singleLine);
    editText.setMinLines(lines);
    editText.setMaxLines(lines);
    editText.setLines(lines);
}
 
public void apply(EditText editText) {
  editText.setText(mText);
  editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
  editText.setMinLines(mMinLines);
  editText.setMaxLines(mMaxLines);
  editText.setInputType(mInputType);
  editText.setHint(mPlaceholder);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    editText.setBreakStrategy(mBreakStrategy);
  }
}
 
源代码8 项目: V2EX   文件: DialogUtil.java
public static void showInputDialog(Context context,
                                   String title,
                                   String msg,
                                   String defaultValue,
                                   DialogListener<String> dialogListener){

    AlertDialog.Builder builder = new AlertDialog.Builder(context, getTheme(context));

    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    FrameLayout frameLayout = new FrameLayout(context);
    frameLayout.setLayoutParams(layoutParams);
    EditText editText = new EditText(context);
    editText.setLayoutParams(layoutParams);
    editText.setMaxLines(1);
    frameLayout.addView(editText);
    frameLayout.setPadding(35,25,35,25);

    if (msg != null){
        builder.setMessage(msg);
    }
    if (defaultValue != null){
        editText.setText(defaultValue);
    }
    builder.setTitle(title)
            .setView(frameLayout)
            .setPositiveButton(R.string.confirm, (dialog, which) -> {
                dialogListener.onResult(editText.getText().toString());
                dialog.dismiss();
            })
            .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss())
            .create()
            .show();
}
 
源代码9 项目: NetCloud_android   文件: HostInputDialog.java
public void show(int inputType){
    if(mHostInputDialog != null){
        return;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    LinearLayout cnt = new LinearLayout(mContext);
    cnt.setBackgroundResource(R.drawable.list_item_bg);
    cnt.setOrientation(LinearLayout.VERTICAL);
    cnt.setGravity(Gravity.CENTER_HORIZONTAL);
    int vp = ScreenUtils.dp2px(12);
    int hp = (int) ResTools.getDimen(R.dimen.hor_padding);
    cnt.setPadding(hp, vp, hp, vp);

    final EditText editText = new EditText(mContext);
    editText.setBackgroundColor(ResTools.getColor(R.color.background));
    editText.setMaxLines(1);
    editText.setSingleLine();
    if(mOriginContent != null){
        editText.setText(mOriginContent);
    }
    editText.setFilters(new InputFilter[] {new InputFilter.LengthFilter(60)});
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

    if(inputType > 0){
        editText.setInputType(inputType);
    }

    cnt.addView(editText);

    TextView ok = new TextView(mContext);
    ok.setText(R.string.add);
    ok.setGravity(Gravity.CENTER);
    ok.setBackgroundResource(R.drawable.button_blue);
    ok.setTextColor(ResTools.getColor(R.color.blue));
    ok.setTextSize(TypedValue.COMPLEX_UNIT_PX, (int)ResTools.getDimen(R.dimen.textsize1));
    ok.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String host = editText.getText().toString();
            mCallback.onHostInput(host);
        }
    });

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ScreenUtils.dp2px(80), ScreenUtils.dp2px(32));
    lp.gravity = Gravity.CENTER_HORIZONTAL;
    lp.topMargin = ScreenUtils.dp2px(16);
    cnt.addView(ok, lp);

    builder.setView(cnt);

    mHostInputDialog = builder.create();
    mHostInputDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mHostInputDialog = null;
            mCallback.onDismiss();
        }
    });

    mHostInputDialog.show();
    editText.requestFocus();
}
 
源代码10 项目: BubbleAlert   文件: BblContentFragment.java
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    clickHandler = new ClickHandler(this);

    txtDialogTitle = (TextView) view.findViewById(R.id.txtDialogTitle);
    txtContent = (TextView) view.findViewById(R.id.txtContent);
    btnOk = (TextView) view.findViewById(R.id.btnOk);
    btnExit = (TextView) view.findViewById(R.id.btnExit);
    btnCancel = (TextView) view.findViewById(R.id.btnCancel);
    edtLibName = (EditText) view.findViewById(R.id.edtLibName);

    btnOk.setOnClickListener(clickHandler);
    btnExit.setOnClickListener(clickHandler);
    btnCancel.setOnClickListener(clickHandler);

    txtContent.setText(content);
    btnOk.setText(ok);
    btnCancel.setText(cancel);
    btnExit.setText(exit);
    if (!TextUtils.isEmpty(sDialogTitle)) {
        txtDialogTitle.setText(sDialogTitle);
    }

    if (btnCount == 1) {
        btnCancel.setVisibility(View.GONE);
    } else if (btnCount == 3) {
        btnExit.setVisibility(View.VISIBLE);
    }

    int visibility = hasEditText ? View.VISIBLE : View.GONE;

    edtLibName.setVisibility(visibility);
    if (!TextUtils.isEmpty(textContent)) {

        edtLibName.setText(textContent);
    }

    if (!TextUtils.isEmpty(hintText)) {

        edtLibName.setHint(hintText);
    }

    if (isMultiLineEditText) {
        edtLibName.setMaxLines(1);
        edtLibName.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
        edtLibName.setScroller(new Scroller(getContext()));
        edtLibName.setVerticalScrollBarEnabled(true);
        edtLibName.setMovementMethod(new ScrollingMovementMethod());
    }

}
 
源代码11 项目: BigApp_Discuz_Android   文件: WithDelEditText.java
public WithDelEditText(Context context, AttributeSet attrs) {
        super(context, attrs);

        // 方式1获取属性
        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.WithDelEditText);


        hintString = a
                .getString(R.styleable.WithDelEditText_WithDelEditText_hint);

        hintColor = a.getColor(R.styleable.WithDelEditText_WithDelEditText_hint_color, getContext().getResources().getColor(R.color.gray_half_5));

        WithDelEditTextIcon = a
                .getDrawable(R.styleable.WithDelEditText_WithDelEditText_icon);

        WithDelEditTextDeleteIcon = a
                .getDrawable(R.styleable.WithDelEditText_WithDelEditText_delete_icon);


        WithDelEditTextDeleteIcon = a
                .getDrawable(R.styleable.WithDelEditText_WithDelEditText_delete_icon);

        WithDelEditTextBackground = a
                .getDrawable(R.styleable.WithDelEditText_WithDelEditText_background);

        lines = a.getInteger(R.styleable.WithDelEditText_WithDelEditText_lines, 1);
        maxLines = a.getInteger(R.styleable.WithDelEditText_WithDelEditText_maxLines, 1);


        a.recycle();

        View view = LayoutInflater.from(context).inflate(
                R.layout.with_del_edittext, null);

        ivWithDelEditTextDeleteIcon = (ImageView) view
                .findViewById(R.id.iv_with_del_eidttext_delete);
        if (WithDelEditTextDeleteIcon != null)
            ivWithDelEditTextDeleteIcon
                    .setImageDrawable(WithDelEditTextDeleteIcon);

        rl = (RelativeLayout) view
                .findViewById(R.id.rl);
        if (WithDelEditTextBackground != null)
            rl.setBackgroundDrawable(WithDelEditTextBackground);

        et = (EditText) view.findViewById(R.id.et_with_del_edittext);
        if (!TextUtils.isEmpty(hintString))
            et.setHint(hintString);

        et.setHintTextColor(hintColor);

        ivWithDelEditTextIcon = (ImageView) view.findViewById(R.id.iv_with_del_eidttext_icon);
        if (WithDelEditTextIcon != null) {
            ivWithDelEditTextIcon
                    .setImageDrawable(WithDelEditTextIcon);
            ivWithDelEditTextIcon.setVisibility(VISIBLE);
        }

        ivWithDelEditTextDeleteIcon.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                et.setText("");
            }
        });

        et.setLines(lines);
        et.setMaxLines(maxLines);

        // 给编辑框添加文本改变事件
        et.addTextChangedListener(new MyTextWatcher());
        et.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View arg0, boolean arg1) {
                // TODO Auto-generated method stub
//				Log.v("Steel", "arg1:"+arg1+";"+et.hasFocus());
                if (et.hasFocus()) {
                    if (focusCheckListenter != null) {
                        focusCheckListenter.setOnFocusValue(true);
                    }
                } else {
                    if (focusCheckListenter != null) {
                        focusCheckListenter.setOnFocusValue(false);
                    }
                }
            }
        });


        // 把获得的view加载到这个控件中
        addView(view);
    }
 
源代码12 项目: jmessage-android-uikit   文件: ChatView.java
public void initModule(float density, int densityDpi) {
    mChatTitle = (TextView) findViewById(IdHelper.getViewID(mContext, "jmui_title"));
    if (densityDpi <= 160) {
        mChatTitle.setMaxWidth((int)(180 * density + 0.5f));
    }else if (densityDpi <= 240) {
        mChatTitle.setMaxWidth((int)(190 * density + 0.5f));
    }else {
        mChatTitle.setMaxWidth((int)(200 * density + 0.5f));
    }
    mReturnBtn = (ImageButton) findViewById(IdHelper.getViewID(mContext, "jmui_return_btn"));
    mChatListView = (DropDownListView) findViewById(IdHelper.getViewID(mContext, "jmui_chat_list"));
    mVoiceBtn = (RecordVoiceButton) findViewById(IdHelper.getViewID(mContext, "jmui_voice_btn"));
    mChatInputEt = (EditText) findViewById(IdHelper.getViewID(mContext, "jmui_chat_input_et"));
    mSwitchIb = (ImageButton) findViewById(IdHelper.getViewID(mContext, "jmui_switch_voice_ib"));
    mAddFileIb = (ImageButton) findViewById(IdHelper.getViewID(mContext, "jmui_add_file_btn"));
    mTakePhotoIb = (ImageButton) findViewById(IdHelper.getViewID(mContext, "jmui_pick_from_camera_btn"));
    mPickPictureIb = (ImageButton) findViewById(IdHelper.getViewID(mContext, "jmui_pick_from_local_btn"));
    mSendMsgBtn = (Button) findViewById(IdHelper.getViewID(mContext, "jmui_send_msg_btn"));
    mBackground = (LinearLayout) findViewById(IdHelper.getViewID(mContext, "jmui_chat_background"));
    mMoreMenuTl = (TableLayout) findViewById(IdHelper.getViewID(mContext, "jmui_more_menu_tl"));
    mRightBtn = (ImageButton) findViewById(IdHelper.getViewID(mContext, "jmui_right_btn"));
    mGroupNumTv = (TextView) findViewById(IdHelper.getViewID(mContext, "jmui_group_num_tv"));
    mExpressionIb = (ImageButton) findViewById(IdHelper.getViewID(mContext, "jmui_expression_btn"));
    mLocationIb = (ImageButton) findViewById(IdHelper.getViewID(mContext, "jmui_send_location_btn"));
    mSendVideoIb = (ImageButton) findViewById(IdHelper.getViewID(mContext, "jmui_send_video_btn"));

    mBackground.requestFocus();
    mChatInputEt.addTextChangedListener(watcher);
    mChatInputEt.setOnFocusChangeListener(listener);
    mChatInputEt.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    mChatInputEt.setSingleLine(false);
    mChatInputEt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                dismissMoreMenu();
                Log.i("ChatView", "dismissMoreMenu()----------");
            }
            return false;
        }
    });
    mChatInputEt.setMaxLines(4);
    setMoreMenuHeight();
}
 
源代码13 项目: NIM_Android_UIKit   文件: EasyEditDialog.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(mResourceId);

    try {
        LinearLayout root = (LinearLayout) findViewById(R.id.easy_edit_dialog_root);
        ViewGroup.LayoutParams params = root.getLayoutParams();
        params.width = (int) ScreenUtil.getDialogWidth();
        root.setLayoutParams(params);

        if (mTitle != null) {
            mTitleTextView = (TextView) findViewById(R.id.easy_dialog_title_text_view);
            mTitleTextView.setText(mTitle);
        }

        if (mMessage != null) {
            mMessageTextView = (TextView) findViewById(R.id.easy_dialog_message_text_view);
            mMessageTextView.setText(mMessage);
            mMessageTextView.setVisibility(View.VISIBLE);
        }

        mEdit = (EditText) findViewById(R.id.easy_alert_dialog_edit_text);
        mLengthTextView = (TextView) findViewById(R.id.edit_text_length);
        // mEdit.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mMaxEditTextLength) });
        mLengthTextView.setVisibility(mShowEditTextLength ? View.VISIBLE : View.GONE);
        if (inputType != -1) {
            mEdit.setInputType(inputType);
        }
        mEdit.addTextChangedListener(new EditTextWatcher(mEdit, mLengthTextView, mMaxEditTextLength,
                mShowEditTextLength));

        if (!TextUtils.isEmpty(mEditHint)) {
            mEdit.setHint(mEditHint);
        }
        if (mMaxLines > 0) {
            mEdit.setMaxLines(mMaxLines);
        }
        if (mSingleLine) {
            mEdit.setSingleLine();
        }

        mPositiveBtn = (Button) findViewById(R.id.easy_dialog_positive_btn);
        if (mPositiveBtnStrResId != 0) {
            mPositiveBtn.setText(mPositiveBtnStrResId);
        }
        mPositiveBtn.setOnClickListener(mPositiveBtnListener);

        mNegativeBtn = (Button) findViewById(R.id.easy_dialog_negative_btn);
        if (mNegativeBtnStrResId != 0) {
            mNegativeBtn.setText(mNegativeBtnStrResId);
        }
        mNegativeBtn.setOnClickListener(mNegativeBtnListener);
        mNegativeBtn.setVisibility(View.VISIBLE);
        findViewById(R.id.easy_dialog_btn_divide_view).setVisibility(View.VISIBLE);
    } catch (Exception e) {
        e.printStackTrace();
    }
}