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

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

源代码1 项目: nfcspy   文件: ActivityMain.java
private void setDiscoveryDelay() {

		final EditText input = new EditText(this);
		input.setHint(this.getString(R.string.hint_discoverydelay));
		input.setText(Integer.toString(nfc.getDiscoveryDelay()));
		input.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
		input.setKeyListener(DigitsKeyListener.getInstance("01234567890"));
		input.setSingleLine(true);

		SetDelayHelper helper = new SetDelayHelper(nfc, input);

		new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT)
				.setTitle(R.string.action_discoverydelay)
				.setMessage(R.string.lab_discoverydelay).setView(input)
				.setPositiveButton(R.string.action_ok, helper)
				.setNegativeButton(R.string.action_cancel, helper).show();
	}
 
源代码2 项目: NewXmPluginSDK   文件: MLAlertDialog.java
/**
 * 该方法不能与setView()方法同时使用
 * 
 * @return
 */
public Builder setInputView(String str, boolean singleLine) {
    View view = View.inflate(mContext, R.layout.ml_alert_dialog_input_view, null);
    setView(view,
            mContext.getResources().getDimensionPixelSize(
                    R.dimen.alertdialog_button_panel_padding_horizontal),
            0,
            mContext.getResources().getDimensionPixelSize(
                    R.dimen.alertdialog_button_panel_padding_horizontal),
            mContext.getResources().getDimensionPixelSize(
                    R.dimen.alertdialog_custom_panel_padding_bottom));
    EditText et = ((EditText) view.findViewById(R.id.input_text));
    et.setSingleLine(singleLine);
    if (!TextUtils.isEmpty(str))
        et.setHint(str);
    et.requestFocus();
    return this;
}
 
源代码3 项目: Onosendai   文件: DialogHelper.java
public static void askString (final Context context, final String msg,
		final String oldValue, final boolean multiLine, final boolean spellCheck,
		final Listener<String> onString) {
	final AlertDialog.Builder dlgBld = new AlertDialog.Builder(context);
	dlgBld.setMessage(msg);
	final EditText editText = new EditText(context);
	editText.setSelectAllOnFocus(true);
	if (oldValue != null) editText.setText(oldValue);
	if (!multiLine) editText.setSingleLine();
	if (!spellCheck) editText.setInputType(editText.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
	editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
	dlgBld.setView(editText);
	dlgBld.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
		@Override
		public void onClick (final DialogInterface dialog, final int which) {
			dialog.dismiss();
			onString.onAnswer(editText.getText().toString().trim());
		}
	});
	dlgBld.setNegativeButton(android.R.string.cancel, DLG_CANCEL_CLICK_LISTENER);
	dlgBld.show();
}
 
@ActionMethod(ids = R.id.bookmenu_rename)
public void renameBook(final ActionEx action) {
    final File file = action.getParameter("source");
    if (file == null) {
        return;
    }

    final FileUtils.FilePath path = FileUtils.parseFilePath(file.getAbsolutePath(), CodecType.getAllExtensions());
    final EditText input = new AppCompatEditText(getManagedComponent());
    input.setSingleLine();
    input.setText(path.name);
    input.selectAll();

    final ActionDialogBuilder builder = new ActionDialogBuilder(this.getManagedComponent(), this);
    builder.setTitle(R.string.book_rename_title);
    builder.setMessage(R.string.book_rename_msg);
    builder.setView(input);
    builder.setPositiveButton(R.id.actions_doRenameBook, new Constant("source", file), new Constant("file", path),
            new EditableValue("input", input));
    builder.setNegativeButton().show();
}
 
源代码5 项目: 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));
}
 
@ActionMethod(ids = R.id.bookmenu_rename)
public void renameBook(final ActionEx action) {
    final BookNode book = action.getParameter("source");
    if (book == null) {
        return;
    }

    final FileUtils.FilePath file = FileUtils.parseFilePath(book.path, CodecType.getAllExtensions());
    final EditText input = new AppCompatEditText(getManagedComponent());
    input.setSingleLine();
    input.setText(file.name);
    input.selectAll();

    final ActionDialogBuilder builder = new ActionDialogBuilder(getContext(), this);
    builder.setTitle(R.string.book_rename_title);
    builder.setMessage(R.string.book_rename_msg);
    builder.setView(input);
    builder.setPositiveButton(R.id.actions_doRenameBook, new Constant("source", book), new Constant("file", file),
            new EditableValue("input", input));
    builder.setNegativeButton().show();
}
 
源代码7 项目: TextFiction   文件: CompassFragment.java
@Override
public boolean onLongClick(View v) {
	editCommand = new EditText(getActivity());
	editCommand.setSingleLine(true);
	try {
		editCommand.setText(v.getTag().toString());
		editCommand.setTag(v);
	}
	catch (Exception e) {
		Log.w(getClass().getName(), e); // ?!
	}
	AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
	builder.setView(editCommand);
	builder.setTitle(R.string.title_edit_direction);
	builder.setPositiveButton(android.R.string.ok, this);
	builder.show();
	return true;
}
 
源代码8 项目: MCPDict   文件: FavoriteDialogs.java
public static void add(final char unicode) {
    final EditText editText = new EditText(activity);
    editText.setHint(R.string.favorite_add_hint);
    editText.setSingleLine(false);
    new AlertDialog.Builder(activity)
        .setIcon(R.drawable.ic_star_yellow)
        .setTitle(String.format(activity.getString(R.string.favorite_add), unicode))
        .setView(editText)
        .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String comment = editText.getText().toString();
                UserDatabase.insertFavorite(unicode, comment);
                String message = String.format(activity.getString(R.string.favorite_add_done), unicode);
                Boast.showText(activity, message, Toast.LENGTH_SHORT);
                FavoriteFragment fragment = activity.getFavoriteFragment();
                if (fragment != null) {
                    fragment.notifyAddItem();
                }
                activity.getCurrentFragment().refresh();
            }
        })
        .setNegativeButton(R.string.cancel, null)
        .show();
}
 
源代码9 项目: APDE   文件: APDE.java
public EditText createAlertDialogEditText(Activity context, AlertDialog.Builder builder, String content, boolean selectAll) {
	final EditText input = new EditText(context);
	input.setSingleLine();
	input.setText(content);
	if (selectAll) {
		input.selectAll();
	}
	
	// http://stackoverflow.com/a/27776276/
	FrameLayout frameLayout = new FrameLayout(context);
	FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
	
	// http://stackoverflow.com/a/35211225/
	float dpi = getResources().getDisplayMetrics().density;
	params.leftMargin = (int) (19 * dpi);
	params.topMargin = (int) (5 * dpi);
	params.rightMargin = (int) (14 * dpi);
	params.bottomMargin = (int) (5 * dpi);
	
	frameLayout.addView(input, params);
	
	builder.setView(frameLayout);
	
	return input;
}
 
源代码10 项目: Leisure   文件: MainActivity.java
private void showSearchDialog(){
    final EditText editText = new EditText(this);
    editText.setGravity(Gravity.CENTER);
    editText.setSingleLine();
    new AlertDialog.Builder(this)
            .setTitle(getString(R.string.text_search_books))
            .setIcon(R.mipmap.ic_search)
            .setView(editText)
            .setPositiveButton(getString(R.string.text_ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if(Utils.hasString(editText.getText().toString())){
                        Intent intent = new Intent(MainActivity.this,SearchBooksActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putString(getString(R.string.id_search_text),editText.getText().toString());
                        intent.putExtras(bundle);
                        startActivity(intent);
                    }
                }
            }).show();
}
 
源代码11 项目: SortableTableView   文件: CarTableDataAdapter.java
private View renderEditableCatName(final Car car) {
    final EditText editText = new EditText(getContext());
    editText.setText(car.getName());
    editText.setPadding(20, 10, 20, 10);
    editText.setTextSize(TEXT_SIZE);
    editText.setSingleLine();
    editText.addTextChangedListener(new CarNameUpdater(car));
    return editText;
}
 
源代码12 项目: java-n-IDE-for-Android   文件: DialogHelper.java
public static void initFilenameInputDialog(MaterialDialog show) {
    final EditText editText = show.getInputEditText();
    editText.setSingleLine();
    editText.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

    // create an initial filename to suggest to the user
    String filename = createLogFilename();
    editText.setText(filename);

    // highlight everything but the .txt at the end
    editText.setSelection(0, filename.length() - 4);
}
 
源代码13 项目: htmlview   文件: NativeElementView.java
static NativeElementView createTextArea(final Context context, final Element element) {
  int textSize = element.getScaledPx(Style.FONT_SIZE);
  EditText editText = new EditText(context);
  editText.setSingleLine(false);
  editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
  editText.setGravity(Gravity.TOP);
  // TODO: Calculate lines based on height if fixed.
  editText.setLines(element.getAttributeInt("rows", 2));
  editText.setVerticalScrollBarEnabled(true);
  LayoutParams params = new LayoutParams(0, LayoutParams.WRAP_CONTENT);
  editText.setLayoutParams(params);
  NativeElementView result = new NativeElementView(context, element, false, editText);
  result.reset();
  return result;
}
 
源代码14 项目: edslite   文件: RenameFileDialog.java
@NonNull
   @Override
public Dialog onCreateDialog(Bundle savedInstanceState) 
{		
	AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
	alert.setMessage(getString(R.string.enter_new_file_name));

	// Set an EditText view to get user input
	final String filename = getArguments().getString(ARG_FILENAME);
	final EditText input = new EditText(getActivity());
	input.setId(android.R.id.edit);
	input.setSingleLine();
	input.setText(filename);
	StringPathUtil spu = new StringPathUtil(filename);
	String fnWoExt = spu.getFileNameWithoutExtension();
	if(fnWoExt.length() > 0)
		input.setSelection(0, fnWoExt.length());
	alert.setView(input);

	alert.setPositiveButton(getString(android.R.string.ok),
			(dialog, whichButton) -> renameFile(input.getText().toString()));

	alert.setNegativeButton(android.R.string.cancel,
			(dialog, whichButton) ->
			{
                   // Canceled.
               });

	return alert.create();
}
 
源代码15 项目: matlog   文件: DialogHelper.java
public static void initFilenameInputDialog(MaterialDialog show) {
    final EditText editText = show.getInputEditText();
    editText.setSingleLine();
    editText.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

    // create an initial filename to suggest to the user
    String filename = createLogFilename();
    editText.setText(filename);

    // highlight everything but the .txt at the end
    editText.setSelection(0, filename.length() - 4);
}
 
源代码16 项目: document-viewer   文件: ViewerActivityController.java
public void askPassword(final String fileName, final int promtId) {
    final EditText input = new AppCompatEditText(getManagedComponent());
    input.setSingleLine(true);
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

    final ActionDialogBuilder builder = new ActionDialogBuilder(getManagedComponent(), this);
    builder.setTitle(fileName).setMessage(promtId).setView(input);
    builder.setPositiveButton(R.id.actions_redecodingWithPassword, new EditableValue("input", input));
    builder.setNegativeButton(R.id.mainmenu_close).show();
}
 
源代码17 项目: mobile-manager-tool   文件: PlaylistDialog.java
@Override
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);
    setContentView(new LinearLayout(this));

    action = getIntent().getAction();

    mRenameId = icicle != null ? icicle.getLong(INTENT_KEY_RENAME) : getIntent().getLongExtra(
            INTENT_KEY_RENAME, -1);
    mList = icicle != null ? icicle.getLongArray(INTENT_PLAYLIST_LIST) : getIntent()
            .getLongArrayExtra(INTENT_PLAYLIST_LIST);
    if (INTENT_RENAME_PLAYLIST.equals(action)) {
        mOriginalName = nameForId(mRenameId);
        mDefaultName = icicle != null ? icicle.getString(INTENT_KEY_DEFAULT_NAME)
                : mOriginalName;
    } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
        mDefaultName = icicle != null ? icicle.getString(INTENT_KEY_DEFAULT_NAME)
                : makePlaylistName();
        mOriginalName = mDefaultName;
    }

    DisplayMetrics dm = new DisplayMetrics();
    dm = getResources().getDisplayMetrics();

    mPlaylistDialog = new AlertDialog.Builder(this).create();
    mPlaylistDialog.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    if (action != null && mRenameId >= 0 && mOriginalName != null || mDefaultName != null) {

        mPlaylist = new EditText(this);
        mPlaylist.setSingleLine(true);
        mPlaylist.setText(mDefaultName);
        mPlaylist.setSelection(mDefaultName.length());
        mPlaylist.addTextChangedListener(this);

        mPlaylistDialog.setIcon(android.R.drawable.ic_dialog_info);
        String promptformat;
        String prompt = "";
        if (INTENT_RENAME_PLAYLIST.equals(action)) {
            promptformat = getString(R.string.rename_playlist);
            prompt = String.format(promptformat, mOriginalName, mDefaultName);
        } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
            promptformat = getString(R.string.new_playlist);
            prompt = String.format(promptformat, mDefaultName);
        }

        mPlaylistDialog.setTitle(prompt);
        mPlaylistDialog.setView(mPlaylist, (int)(8 * dm.density), (int)(8 * dm.density),
                (int)(8 * dm.density), (int)(4 * dm.density));
        if (INTENT_RENAME_PLAYLIST.equals(action)) {
            mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save),
                    mRenamePlaylistListener);
            mPlaylistDialog.setOnShowListener(this);
        } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
            mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save),
                    mCreatePlaylistListener);
        }
        mPlaylistDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        finish();
                    }
                });
        mPlaylistDialog.setOnCancelListener(this);
        mPlaylistDialog.show();
    } else {
        Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
        finish();
    }

}
 
源代码18 项目: TwistyTimer   文件: AlgDialog.java
@Override
public void onClick(View view) {
    final DatabaseHandler dbHandler = TwistyTimer.getDBHandler();

    switch (view.getId()) {
        case R.id.editButton:
            MaterialDialog dialog = ThemeUtils.roundDialog(mContext, new MaterialDialog.Builder(mContext)
                    .title(R.string.edit_algorithm)
                    .input("", algorithm.getAlgs(), (dialog1, input) -> {
                        algorithm.setAlgs(input.toString());
                        dbHandler.updateAlgorithmAlg(mId, input.toString());
                        algText.setText(input.toString());
                        updateList();
                    })
                    .inputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE)
                    .positiveText(R.string.action_done)
                    .negativeText(R.string.action_cancel)
                    .build());
            EditText editText = dialog.getInputEditText();
            if (editText != null) {
                editText.setSingleLine(false);
                editText.setLines(5);
                editText.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
                editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            }
            dialog.show();
            break;

        case R.id.progressButton:
            final AppCompatSeekBar seekBar = (AppCompatSeekBar) LayoutInflater.from(mContext).inflate(R.layout.dialog_progress, null);
            seekBar.setProgress(algorithm.getProgress());
            ThemeUtils.roundAndShowDialog(mContext, new MaterialDialog.Builder(mContext)
                    .title(R.string.dialog_set_progress)
                    .customView(seekBar, false)
                    .positiveText(R.string.action_update)
                    .negativeText(R.string.action_cancel)
                    .onPositive((dialog12, which) -> {
                        int seekProgress = seekBar.getProgress();
                        algorithm.setProgress(seekProgress);
                        dbHandler.updateAlgorithmProgress(mId, seekProgress);
                        progressBar.setProgress(seekProgress);
                        updateList();
                    })
                    .build());
            break;

        case R.id.revertButton:
            ThemeUtils.roundAndShowDialog(mContext, new MaterialDialog.Builder(mContext)
                    .title(R.string.dialog_revert_title_confirmation)
                    .content(R.string.dialog_revert_content_confirmation)
                    .positiveText(R.string.action_reset)
                    .negativeText(R.string.action_cancel)
                    .onPositive((dialog13, which) -> {
                        algorithm.setAlgs(AlgUtils.getDefaultAlgs(algorithm.getSubset(), algorithm.getName()));
                        dbHandler.updateAlgorithmAlg(mId, algorithm.getAlgs());
                        algText.setText(algorithm.getAlgs());
                    })
                    .build());
            break;
    }
}
 
源代码19 项目: delion   文件: AutofillProfileEditor.java
private void resetFormFields(int countryCodeIndex, boolean autoFocusFirstField) {
    // Save field text so we can restore it after updating the fields for the current country,
    // and reset mAddressFields.
    String[] fieldText = new String[mAddressFields.length];
    for (int i = 0; i < mAddressFields.length; i++) {
        if (mAddressFields[i] != null) {
            fieldText[i] = mAddressFields[i].getEditText().getText().toString();
            mAddressFields[i] = null;
        }
    }

    // Remove all address form fields.
    mWidgetRoot.removeAllViews();

    // Get address fields for the selected country.
    List<AddressUiComponent> fields = mAutofillProfileBridge.getAddressUiComponents(
            mCountryCodes.get(countryCodeIndex),
            mLanguageCodeString);
    if (!mUseSavedProfileLanguage) {
        mLanguageCodeString = mAutofillProfileBridge.getCurrentBestLanguageCode();
    }

    // Create form fields and focus the first field if autoFocusFirstField is true.
    boolean firstField = true;
    for (AddressUiComponent field : fields) {
        CompatibilityTextInputLayout fieldFloatLabel =
                (CompatibilityTextInputLayout) mInflater.inflate(
                        R.layout.preference_address_float_label_layout, mWidgetRoot, false);
        fieldFloatLabel.setHint(field.label);

        EditText fieldEditText = fieldFloatLabel.getEditText();
        fieldEditText.setContentDescription(field.label);
        fieldEditText.addTextChangedListener(this);
        if (field.id == AddressField.STREET_ADDRESS) {
            fieldEditText.setSingleLine(false);
        }

        mAddressFields[field.id] = fieldFloatLabel;
        mWidgetRoot.addView(fieldFloatLabel);

        if (firstField && autoFocusFirstField) {
            fieldEditText.requestFocus();
            firstField = false;
        }
    }

    // Add back saved field text.
    for (int i = 0; i < mAddressFields.length; i++) {
        if (mAddressFields[i] != null && fieldText[i] != null
                && !TextUtils.isEmpty(fieldText[i])) {
            mAddressFields[i].getEditText().setText(fieldText[i]);
        }
    }
}
 
源代码20 项目: AndroidChromium   文件: AutofillProfileEditor.java
private void resetFormFields(int countryCodeIndex, boolean autoFocusFirstField) {
    // Save field text so we can restore it after updating the fields for the current country,
    // and reset mAddressFields.
    String[] fieldText = new String[mAddressFields.length];
    for (int i = 0; i < mAddressFields.length; i++) {
        if (mAddressFields[i] != null) {
            fieldText[i] = mAddressFields[i].getEditText().getText().toString();
            mAddressFields[i] = null;
        }
    }

    // Remove all address form fields.
    mWidgetRoot.removeAllViews();

    // Get address fields for the selected country.
    List<AddressUiComponent> fields = mAutofillProfileBridge.getAddressUiComponents(
            mCountryCodes.get(countryCodeIndex),
            mLanguageCodeString);
    if (!mUseSavedProfileLanguage) {
        mLanguageCodeString = mAutofillProfileBridge.getCurrentBestLanguageCode();
    }

    // Create form fields and focus the first field if autoFocusFirstField is true.
    boolean firstField = true;
    for (AddressUiComponent field : fields) {
        CompatibilityTextInputLayout fieldFloatLabel =
                (CompatibilityTextInputLayout) mInflater.inflate(
                        R.layout.preference_address_float_label_layout, mWidgetRoot, false);
        fieldFloatLabel.setHint(field.label);

        EditText fieldEditText = fieldFloatLabel.getEditText();
        fieldEditText.addTextChangedListener(this);
        if (field.id == AddressField.STREET_ADDRESS) {
            fieldEditText.setSingleLine(false);
        }

        mAddressFields[field.id] = fieldFloatLabel;
        mWidgetRoot.addView(fieldFloatLabel);

        if (firstField && autoFocusFirstField) {
            fieldEditText.requestFocus();
            firstField = false;
        }
    }

    // Add back saved field text.
    for (int i = 0; i < mAddressFields.length; i++) {
        if (mAddressFields[i] != null && fieldText[i] != null
                && !TextUtils.isEmpty(fieldText[i])) {
            mAddressFields[i].getEditText().setText(fieldText[i]);
        }
    }
}