下面列出了android.widget.EditText#setHorizontallyScrolling ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
/**
* Ask the user for a file name, create this file and choose it.
* ({@link #onFileChosen(View)}).
*/
private void onNewFile() {
final Context cont = this;
// Ask user for filename.
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setLines(1);
input.setHorizontallyScrolling(true);
new AlertDialog.Builder(this)
.setTitle(R.string.dialog_new_file_title)
.setMessage(R.string.dialog_new_file)
.setIcon(android.R.drawable.ic_menu_add)
.setView(input)
.setPositiveButton(R.string.action_ok,
(dialog, whichButton) -> {
if (input.getText() != null
&& !input.getText().toString().equals("")) {
File file = new File(mDir.getPath(),
input.getText().toString());
if (file.exists()) {
Toast.makeText(cont,
R.string.info_file_already_exists,
Toast.LENGTH_LONG).show();
return;
}
Intent intent = new Intent();
intent.putExtra(EXTRA_CHOSEN_FILE, file.getPath());
setResult(Activity.RESULT_OK, intent);
finish();
} else {
// Empty name is not allowed.
Toast.makeText(cont, R.string.info_empty_file_name,
Toast.LENGTH_LONG).show();
}
})
.setNegativeButton(R.string.action_cancel,
(dialog, whichButton) -> {
// Do nothing.
}).show();
}
/**
* Check if it is a valid key file
* ({@link #isValidKeyFileErrorToast()}),
* ask user for a save name and then call
* {@link Common#checkFileExistenceAndSave(File, String[], boolean,
* Context, IActivityThatReactsToSave)}
* @see Common#checkFileExistenceAndSave(File, String[], boolean, Context,
* IActivityThatReactsToSave)
* @see #isValidKeyFileErrorToast()
*/
private void onSave() {
if (!isValidKeyFileErrorToast()) {
return;
}
final File path = Common.getFileFromStorage(Common.HOME_DIR + "/" +
Common.KEYS_DIR);
final Context cont = this;
final IActivityThatReactsToSave activity =
this;
// Ask user for filename.
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setLines(1);
input.setHorizontallyScrolling(true);
input.setText(mFileName);
input.setSelection(input.getText().length());
new AlertDialog.Builder(this)
.setTitle(R.string.dialog_save_keys_title)
.setMessage(R.string.dialog_save_keys)
.setIcon(android.R.drawable.ic_menu_save)
.setView(input)
.setPositiveButton(R.string.action_ok,
(dialog, whichButton) -> {
if (input.getText() != null
&& !input.getText().toString().equals("")) {
File file = new File(path.getPath(),
input.getText().toString());
Common.checkFileExistenceAndSave(file, mLines,
false, cont, activity);
} else {
// Empty name is not allowed.
Toast.makeText(cont, R.string.info_empty_file_name,
Toast.LENGTH_LONG).show();
}
})
.setNegativeButton(R.string.action_cancel,
(dialog, whichButton) -> mCloseAfterSuccessfulSave = false).show();
}
/**
* Check if the external storage is writable
* {@link Common#isExternalStorageWritableErrorToast(Context)},
* ask user for a save name and then call
* {@link Common#checkFileExistenceAndSave(File, String[], boolean,
* Context, IActivityThatReactsToSave)}.
* This is a helper function for {@link #saveDump()}
* and {@link #saveKeys()}.
* @param data Data to save.
* @param fileName Name of the file.
* @param isDump True if data contains a dump. False if data contains keys.
* @param titleId Resource ID for the title of the dialog.
* @param messageId Resource ID for the message of the dialog.
* @see Common#isExternalStorageWritableErrorToast(Context)
* @see Common#checkFileExistenceAndSave(File, String[], boolean,
* Context, IActivityThatReactsToSave)
*/
private void saveFile(final String[] data, final String fileName,
final boolean isDump, int titleId, int messageId) {
if (!Common.getPreferences().getBoolean(UseInternalStorage.toString(),
false) && !Common.isExternalStorageWritableErrorToast(this)) {
return;
}
String targetDir = (isDump) ? Common.DUMPS_DIR : Common.KEYS_DIR;
final File path = Common.getFileFromStorage(
Common.HOME_DIR + "/" + targetDir);
final Context context = this;
final IActivityThatReactsToSave activity = this;
// Ask user for filename.
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setLines(1);
input.setHorizontallyScrolling(true);
input.setText(fileName);
input.setSelection(input.getText().length());
new AlertDialog.Builder(this)
.setTitle(titleId)
.setMessage(messageId)
.setIcon(android.R.drawable.ic_menu_save)
.setView(input)
.setPositiveButton(R.string.action_save,
(dialog, whichButton) -> {
if (input.getText() != null
&& !input.getText().toString().equals("")) {
File file = new File(path.getPath(),
input.getText().toString());
Common.checkFileExistenceAndSave(file, data,
isDump, context, activity);
if (isDump) {
mDumpName = file.getName();
} else {
mKeysName = file.getName();
}
} else {
// Empty name is not allowed.
Toast.makeText(context, R.string.info_empty_file_name,
Toast.LENGTH_LONG).show();
}
})
.setNegativeButton(R.string.action_cancel,
(dialog, whichButton) -> mCloseAfterSuccessfulSave = false).show();
onUpdateColors(null);
}