下面列出了android.widget.EditText#setRawInputType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
setOrientation(VERTICAL);
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.number_picker, this, true);
mHandler = new Handler();
InputFilter inputFilter = new NumberPickerInputFilter();
mNumberInputFilter = new NumberRangeKeyListener();
mIncrementButton = (NumberPickerButton) findViewById(R.id.increment);
mIncrementButton.setOnClickListener(this);
mIncrementButton.setOnLongClickListener(this);
mIncrementButton.setNumberPicker(this);
mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement);
mDecrementButton.setOnClickListener(this);
mDecrementButton.setOnLongClickListener(this);
mDecrementButton.setNumberPicker(this);
mText = (EditText) findViewById(R.id.timepicker_input);
mText.setOnFocusChangeListener(this);
mText.setFilters(new InputFilter[] {inputFilter});
mText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
if (!isEnabled()) {
setEnabled(false);
}
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
EditText input = new EditText(getContext());
input.setInputType(InputType.TYPE_CLASS_NUMBER);
input.setRawInputType(Configuration.KEYBOARD_12KEY);
DialogInterface.OnClickListener positive = (dialog, whichButton) -> {
if (input.getText().length() > 0)
parent.goToPage(Integer.parseInt(input.getText().toString()));
};
AlertDialog materialDialog = new MaterialAlertDialogBuilder(requireContext())
.setView(input)
.setPositiveButton(android.R.string.ok, positive)
.setNegativeButton(android.R.string.cancel, null)
.create();
materialDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
return materialDialog;
}
public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
setOrientation(VERTICAL);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.number_picker, this, true);
mHandler = new Handler();
InputFilter inputFilter = new NumberPickerInputFilter();
mNumberInputFilter = new NumberRangeKeyListener();
mIncrementButton = (NumberPickerButton) findViewById(R.id.increment);
mIncrementButton.setOnClickListener(this);
mIncrementButton.setOnLongClickListener(this);
mIncrementButton.setNumberPicker(this);
mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement);
mDecrementButton.setOnClickListener(this);
mDecrementButton.setOnLongClickListener(this);
mDecrementButton.setNumberPicker(this);
mText = (EditText) findViewById(R.id.timepicker_input);
mText.setOnFocusChangeListener(this);
mText.setFilters(new InputFilter[] {inputFilter});
mText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
if (!isEnabled()) {
setEnabled(false);
}
}
/**
* {@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);
}
protected void setupCaption(View rootView) {
caption = (EditText) rootView.findViewById(R.id.caption);
caption.setText(originalLabel.getCaptionText());
caption.setImeOptions(EditorInfo.IME_ACTION_DONE);
caption.setRawInputType(InputType.TYPE_CLASS_TEXT);
caption.setOnEditorActionListener(
(textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
caption.clearFocus();
caption.setFocusable(false);
}
return false;
});
caption.setOnTouchListener(
(v, motionEvent) -> {
caption.setFocusableInTouchMode(true);
caption.requestFocus();
return false;
});
caption.setEnabled(false);
experiment
.firstElement()
.subscribe(
experiment -> {
caption.setEnabled(true);
// Move the cursor to the end
caption.post(() -> caption.setSelection(caption.getText().toString().length()));
saved
.happens()
.subscribe(o -> saveCaptionChanges(experiment, caption.getText().toString()));
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_anagrams);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
AssetManager assetManager = getAssets();
try {
InputStream inputStream = assetManager.open("words.txt");
dictionary = new AnagramDictionary(inputStream);
} catch (IOException e) {
Toast toast = Toast.makeText(this, "Could not load dictionary", Toast.LENGTH_LONG);
toast.show();
}
// Set up the EditText box to process the content of the box when the user hits 'enter'
final EditText editText = (EditText) findViewById(R.id.editText);
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setImeOptions(EditorInfo.IME_ACTION_GO);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_GO) {
processWord(editText);
handled = true;
}
return handled;
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_anagrams);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
AssetManager assetManager = getAssets();
try {
InputStream inputStream = assetManager.open("words.txt");
dictionary = new AnagramDictionary(inputStream);
} catch (IOException e) {
Toast toast = Toast.makeText(this, "Could not load dictionary", Toast.LENGTH_LONG);
toast.show();
}
// Set up the EditText box to process the content of the box when the user hits 'enter'
final EditText editText = (EditText) findViewById(R.id.editText);
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setImeOptions(EditorInfo.IME_ACTION_GO);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_GO) {
processWord(editText);
handled = true;
}
return handled;
}
});
}
public static void disableSoftInputFromAppearing(EditText editText) {
if (Build.VERSION.SDK_INT >= 11) {
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setTextIsSelectable(true);
} else {
editText.setRawInputType(InputType.TYPE_NULL);
editText.setFocusable(true);
}
}
/**
* For user removal:
* Shows a prompt for a user serial number. The associated user will be removed.
*/
private void showRemoveUserPromptLegacy() {
if (getActivity() == null || getActivity().isFinishing()) {
return;
}
View view = LayoutInflater.from(getActivity()).inflate(R.layout.simple_edittext, null);
final EditText input = (EditText) view.findViewById(R.id.input);
input.setHint(R.string.enter_user_id);
input.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
new AlertDialog.Builder(getActivity())
.setTitle(R.string.remove_user)
.setView(view)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
boolean success = false;
long serialNumber = -1;
try {
serialNumber = Long.parseLong(input.getText().toString());
UserHandle userHandle = mUserManager
.getUserForSerialNumber(serialNumber);
if (userHandle != null) {
success = mDevicePolicyManager
.removeUser(mAdminComponentName, userHandle);
}
} catch (NumberFormatException e) {
// Error message is printed in the next line.
}
showToast(success ? R.string.user_removed : R.string.failed_to_remove_user);
}
})
.show();
}
@Override
protected void init() {
super.init();
EditText editView = getEditView();
editView.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
}
@Override
protected void init() {
super.init();
mEditView = (EditText) findViewById(R.id.editText);
mEditView.setRawInputType(InputType.TYPE_CLASS_TEXT);
setStyleId(mEditView, CellDescriptor.APPEARANCE_TEXT_VALUE, CellDescriptor.COLOR_VALUE);
}
private View createMeetingLengthTextBox() {
meetingLengthEditText = new EditText(this);
meetingLengthEditText.setGravity(Gravity.CENTER);
meetingLengthEditText.setKeyListener(new DigitsKeyListener());
meetingLengthEditText.setRawInputType(InputType.TYPE_CLASS_PHONE);
meetingLengthEditText.setLayoutParams(new LayoutParams(dipsToPixels(60), LayoutParams.WRAP_CONTENT));
meetingLengthEditText.setText(Integer.toString(meetingLength));
meetingLengthEditText.setLines(1);
meetingLengthSpinner = null;
return meetingLengthEditText;
}
private View createMeetingLengthTextBox() {
meetingLengthEditText = new EditText(this);
meetingLengthEditText.setGravity(Gravity.CENTER);
meetingLengthEditText.setKeyListener(new DigitsKeyListener());
meetingLengthEditText.setRawInputType(InputType.TYPE_CLASS_PHONE);
meetingLengthEditText.setLayoutParams(new LayoutParams(dipsToPixels(60), LayoutParams.WRAP_CONTENT));
meetingLengthEditText.setText(Integer.toString(meetingLength));
meetingLengthEditText.setLines(1);
meetingLengthSpinner = null;
return meetingLengthEditText;
}
@Override
public void onFocusChange(View v, boolean hasFocus) {
setImeVisibility(noteContainer, hasFocus);
EditText editText = (EditText) v;
final int index = getNoteIndex(note);
if(hasFocus){
editText.setRawInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
} else {
if(editText.length() > 0){
((ImageView)note.findViewById(R.id.noteIcon)).setImageResource(R.drawable.ic_drag);
noteContainer.setViewDraggable(note, note.findViewById(R.id.noteIconContainer));
if(index < noteCount){
// note at index set to new value
} else {
// new note added at index
noteCount++;
}
editText.setHint(R.string.note_complete_prompt);
} else {
if(index < noteCount){
// existing note set blank
} else if(index < getLastNoteIndex()){
// too many trailing blank notes, remove last one
final View noteToDelete = noteContainer.getChildAt(firstNoteIndex + index + 1);
noteToDelete.findViewById(R.id.noteText).setEnabled(false); // disable further editing
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(noteToDelete, "alpha", 1, 0);
ObjectAnimator xAnimator = ObjectAnimator.ofFloat(noteToDelete, "x",
noteToDelete.getLeft(), noteToDelete.getLeft() + 30);
AnimatorSet set = new AnimatorSet();
set.playTogether(alphaAnimator, xAnimator);
set.setDuration(200);
set.addListener(new AnimatorListenerAdapter(){
@Override
public void onAnimationEnd(Animator animation) {
noteContainer.removeView(noteToDelete);
}
});
set.start();
}
}
editText.setRawInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
}