下面列出了android.widget.EditText#setSelectAllOnFocus ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void init() {
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_name_input, null);
mView = view.findViewById(R.id.rename_dialog_root);
this.setContentView(mView);
mEtNewName = (EditText) mView.findViewById(R.id.mEtNewName);
mEtOrignalName = (EditText) mView.findViewById(R.id.mEtOriginalName);
mBtnCancel = (Button) mView.findViewById(R.id.mBtnDelDialogCancel);
mBtnOk = (Button) mView.findViewById(R.id.mBtnDelDialogOk);
mEtOrignalName.setEnabled(false);
mEtOrignalName.setText(FileUtils.getFileName(mOrignalPath));
mEtNewName.setText(FileUtils.getFileName(mOrignalPath));
mEtNewName.setSelectAllOnFocus(true);
mParentPath = FileUtils.getParent(mOrignalPath);
mEtNewName.addTextChangedListener(this);
mBtnOk.setOnClickListener(this);
mBtnCancel.setOnClickListener(this);
this.setTitle("重命名文件");
this.setCanceledOnTouchOutside(false);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mEditText = (EditText) findViewById(R.id.dropview_edit);
mDropImage = (ImageView) findViewById(R.id.dropview_image);
mEditText.setSelectAllOnFocus(true);
mDropImage.setImageResource(mDrawableLeft);
if(!TextUtils.isEmpty(mHit)) {
mEditText.setHint(mHit);
}
mDropImage.setOnClickListener(this);
mPopView.setOnItemClickListener(this);
}
private void showSetReadAheadDialog(Misc misc)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.read_ahead_cache_size);
final EditText input = new EditText(this);
input.setText(misc.getValue().substring(0, misc.getValue().length() - 2));
input.setSelectAllOnFocus(true);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
input.setGravity(Gravity.CENTER_HORIZONTAL);
input.requestFocus();
builder.setPositiveButton(getResources().getString(R.string.set), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
RCommand.setReadAhead(input.getText().toString(), MiscTweaksActivity.this);
}
});
builder.setNegativeButton(getResources().getString(R.string.cancel), null);
builder.setView(input);
builder.show();
}
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();
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
String oldName = getArguments().getString(KEY_OLD_NAME);
String collectionSerialized = getArguments().getString(KEY_COLLECTION_GSON);
Gson gson = new Gson();
BooksCollection bookCollection = gson.fromJson(collectionSerialized, BooksCollection.class);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final EditText editText = new EditText(getActivity());
editText.setText(oldName);
editText.setSelectAllOnFocus(true);
builder
.setMessage(R.string.dialog_msg_rename)
.setTitle(R.string.dialog_title_rename)
.setView(editText)
.setPositiveButton(R.string.ok, (dialog, whichButton) -> {
String newName = editText.getText().toString();
mListener.onCollectionRenamed(bookCollection, newName);
})
.setNegativeButton(R.string.cancel, (dialog, whichButton) -> {
dismiss();
});
return builder.create();
}
@Override
protected View getInputView() {
EditText input = new EditText(getContext());
input.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE
| InputType.TYPE_TEXT_FLAG_MULTI_LINE);
input.setHint(R.string.info_enter_comment);
input.setText(getValueAsString(false));
input.setSelectAllOnFocus(true);
return input;
}
public PromptDialog(Context context) {
super(context);
finder = ResoureFinder.getInstance(context);
final LayoutInflater inflater = LayoutInflater.from(getContext());
final RelativeLayout layout = (RelativeLayout) inflater.inflate(
finder.getLayoutId("platform_window_dialog_prompt_layout"), null);
tvDesc = (TextView) layout.findViewById(finder.getId("tv_dialog_input_desc"));
etInput = (EditText) layout.findViewById(finder.getId("et_dialog_input_text"));
etInput.setSelectAllOnFocus(true);
setView(layout);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
EditText etUserId = findViewById(R.id.etUserId);
EditText etNickname = findViewById(R.id.etNickname);
TextView tvVersion = findViewById(R.id.tvVersionInfo);
etUserId.setSelectAllOnFocus(true);
etNickname.setSelectAllOnFocus(true);
String sdkVersion = String.format(getResources().getString(R.string.text_version_info), BuildConfig.VERSION_NAME, SendBird.getSDKVersion());
tvVersion.setText(sdkVersion);
findViewById(R.id.btSignIn).setOnClickListener(v -> {
String userId = etUserId.getText().toString();
// Remove all spaces from userID
userId = userId.replaceAll("\\s", "");
String userNickname = etNickname.getText().toString();
if (TextUtils.isEmpty(userId) || TextUtils.isEmpty(userNickname)) {
return;
}
PreferenceUtils.setUserId(userId);
PreferenceUtils.setNickname(userNickname);
WaitingDialog.show(this);
SendBirdUIKit.connect((user, e) -> {
if (e != null) {
Logger.e(e);
WaitingDialog.dismiss();
return;
}
WaitingDialog.dismiss();
PushUtils.registerPushHandler(new MyFirebaseMessagingService());
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
});
});
}