本文整理匯總了Java中android.support.v7.widget.AppCompatEditText.setInputType方法的典型用法代碼示例。如果您正苦於以下問題:Java AppCompatEditText.setInputType方法的具體用法?Java AppCompatEditText.setInputType怎麽用?Java AppCompatEditText.setInputType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.AppCompatEditText
的用法示例。
在下文中一共展示了AppCompatEditText.setInputType方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: askPassword
import android.support.v7.widget.AppCompatEditText; //導入方法依賴的package包/類
/**
* Dialog which asks the user to enter his password
*
* @param password current encoded password
*/
private void askPassword(final String password) {
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setGravity(Gravity.CENTER);
linearLayout.setPadding(30, 20, 30, 20);
final AppCompatEditText mPassword = new AppCompatEditText(this);
mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
mPassword.setHint(getString(R.string.password));
linearLayout.addView(mPassword);
new AlertDialog.Builder(this).setView(linearLayout).setCancelable(false)
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (mPassword.getText().toString().equals(Utils.decodeString(password)))
new Task().execute();
else {
Utils.toast(getString(R.string.password_wrong), MainActivity.this);
finish();
}
}
}).show();
}
示例2: MageNumberControl
import android.support.v7.widget.AppCompatEditText; //導入方法依賴的package包/類
public MageNumberControl(Context context, AttributeSet attrs, double min, double max) {
super(context, attrs);
this.min = min;
this.max = max;
this.propertyType = MagePropertyType.NUMBER;
AppCompatEditText editText = new AppCompatEditText(context, attrs);
editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
editText.addTextChangedListener(this);
addView(editText);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MageFormElement);
setPropertyKey(typedArray.getString(R.styleable.MageFormElement_propertyKey));
setPropertyType(MagePropertyType.getPropertyType(typedArray.getInt(R.styleable.MageFormElement_propertyType, 0)));
typedArray.recycle();
}
示例3: FormElementTextMultiLineViewHolder
import android.support.v7.widget.AppCompatEditText; //導入方法依賴的package包/類
public FormElementTextMultiLineViewHolder(View v, FormItemEditTextListener listener) {
super(v);
mTextViewTitle = (AppCompatTextView) v.findViewById(R.id.formElementTitle);
mEditTextValue = (AppCompatEditText) v.findViewById(R.id.formElementValue);
mFormCustomEditTextListener = listener;
mEditTextValue.addTextChangedListener(mFormCustomEditTextListener);
mEditTextValue.setMaxLines(4);
mEditTextValue.setSingleLine(false);
mEditTextValue.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
}
示例4: deletePasswordDialog
import android.support.v7.widget.AppCompatEditText; //導入方法依賴的package包/類
private void deletePasswordDialog(final String password) {
if (password.isEmpty()) {
Utils.toast(getString(R.string.set_password_first), getActivity());
return;
}
LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setGravity(Gravity.CENTER);
linearLayout.setPadding(30, 20, 30, 20);
final AppCompatEditText mPassword = new AppCompatEditText(getActivity());
mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
mPassword.setHint(getString(R.string.password));
linearLayout.addView(mPassword);
new AlertDialog.Builder(getActivity()).setView(linearLayout)
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (!mPassword.getText().toString().equals(Utils.decodeString(password))) {
Utils.toast(getString(R.string.password_wrong), getActivity());
return;
}
Utils.saveString("password", "", getActivity());
}
}).show();
}
示例5: deletePasswordDialog
import android.support.v7.widget.AppCompatEditText; //導入方法依賴的package包/類
private void deletePasswordDialog(final String password) {
if (password.isEmpty()) {
Utils.toast(getString(R.string.set_password_first), getActivity());
return;
}
LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setGravity(Gravity.CENTER);
linearLayout.setPadding(30, 20, 30, 20);
final AppCompatEditText mPassword = new AppCompatEditText(getActivity());
mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
mPassword.setHint(getString(R.string.password));
linearLayout.addView(mPassword);
new AlertDialog.Builder(getActivity(),
(Utils.DARKTHEME ? R.style.AlertDialogStyleDark : R.style.AlertDialogStyleLight)).setView(linearLayout)
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (!mPassword.getText().toString().equals(Utils.decodeString(password))) {
Utils.toast(getString(R.string.password_wrong), getActivity());
return;
}
Utils.saveString("password", "", getActivity());
}
}).show();
}
示例6: onCreateDialogLayout
import android.support.v7.widget.AppCompatEditText; //導入方法依賴的package包/類
private void onCreateDialogLayout(@Nullable String restoredName) {
mInputLayout = new TextInputLayout(getContext());
mEditText = new AppCompatEditText(getContext());
mEditText.setInputType(InputType.TYPE_CLASS_TEXT);
mEditText.setHint(R.string.hint_playlist_name);
mEditText.setText(restoredName);
mInputLayout.addView(mEditText);
mInputLayout.setErrorEnabled(true);
mEditText.addTextChangedListener(this);
}
示例7: drawInnerViews
import android.support.v7.widget.AppCompatEditText; //導入方法依賴的package包/類
private void drawInnerViews(Context context, AttributeSet attrs){
float density = context.getResources().getDisplayMetrics().density;
int value16 = (int)(16*density);
int value10 = (int)(10*density);
int value40 = (int)(40*density);
LayoutParams mainLayoutParams = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
mainLayoutParams.setMargins(value16,value16,value16,value16);
setLayoutParams(mainLayoutParams);
//creation & addition of webview
webview = new WebView(context, attrs);
webview.setId(android.R.id.content);
webview.setLayoutParams(
new LayoutBuilder()
.addWidth(LayoutParams.MATCH_PARENT)
.addHeight(LayoutParams.WRAP_CONTENT)
.setMargin(value10,value40,0,0)
.create()
);
webview.getSettings();
webview.setBackgroundColor(Color.argb(0,0,0,0));
addView(webview);
//creation of list view
listView = new ListView(context, attrs);
listView.setId(android.R.id.list);
listView.setLayoutParams(
new LayoutBuilder()
.addWidth(LayoutParams.MATCH_PARENT)
.addHeight(LayoutParams.WRAP_CONTENT)
.setMargin(0,value10,0,0)
.addRule(BELOW, webview.getId() )
.create()
);
addView(listView );
//creation & addition of editText
editTv = new AppCompatEditText(context, attrs);
editTv.setVisibility(GONE);
editTv.setId(android.R.id.text1);
editTv.setLayoutParams(
new LayoutBuilder()
.addWidth(LayoutParams.MATCH_PARENT)
.addHeight(LayoutParams.WRAP_CONTENT)
.setMargin(value10, value10, 0, 0)
.addRule(BELOW, webview.getId())
.create()
);
editTv.setInputType(InputType.TYPE_CLASS_TEXT);
editTv.setImeOptions(EditorInfo.IME_ACTION_DONE);
addView(editTv );
}
示例8: showValueDialog
import android.support.v7.widget.AppCompatEditText; //導入方法依賴的package包/類
private void showValueDialog() {
/*
Ideally, the View that this ViewHolder wraps would have the EditText directly
in it without doing the trickery below where it disguises a TextView as an EditText
and opens an AlertDialog, but there are severe penalties with nesting EditTexts in
a RecyclerView with a LinearLayoutManager. With no code in the ReyclerView
Adapter's .onBindViewHolder() method, GC will kick in frequently when scrolling
to free ~2MB from the heap while pausing for around 60ms (which may also be
complimented by extra layout calls with the EditText). This has been previously
reported to Google's AOSP bug tracker which provides more insight into this problem
https://code.google.com/p/android/issues/detail?id=82586 (closed Feb '15)
There are some workarounds to this issue, but the most practical suggestions that
keep the previously mentioned layout are to use a ListView or to extend EditText
or LinearLayout Manager (which either cause problems in themselves, don't work,
or both).
The solution used here simply avoids the problem all together by not nesting an
EditText in a RecyclerView. When an EditText is needed, the user is prompted with
an AlertDialog. It's not the best UX, but it's the most practical one for now.
10/8/15
*/
TextInputLayout inputLayout = new TextInputLayout(mContext);
AppCompatEditText editText = new AppCompatEditText(mContext);
editText.setInputType(mEnumeratedRule.getInputType());
inputLayout.addView(editText);
Resources res = mContext.getResources();
String type = res.getStringArray(R.array.auto_plist_types)[getSelectedType()];
String match = res.getString(mEnumeratedRule.getNameRes()).toLowerCase();
AlertDialog valueDialog = new AlertDialog.Builder(mContext)
.setMessage(type + " " + match)
.setView(inputLayout)
.setNegativeButton(R.string.action_cancel, null)
.setPositiveButton(R.string.action_done,
(dialog, which) -> {
String value = editText.getText().toString().trim();
if (editText.getInputType() == InputType.TYPE_CLASS_NUMBER) {
// Verify the input if this rule needs a numeric value
if (TextUtils.isDigitsOnly(value)) {
mFactory.setValue(value);
} else {
// If the user inputted something that's not a number, reset it
mFactory.setValue("0");
}
} else {
mFactory.setValue(value);
}
apply();
notifyPropertyChanged(BR.valueText);
})
.create();
valueDialog.getWindow().setSoftInputMode(SOFT_INPUT_STATE_VISIBLE);
valueDialog.show();
int padding = (int) mContext.getResources().getDimension(R.dimen.alert_padding);
((View) inputLayout.getParent()).setPadding(
padding - inputLayout.getPaddingLeft(), 0,
padding - inputLayout.getPaddingRight(), 0);
editText.setText(mFactory.getValue());
editText.setSelection(mFactory.getValue().length());
editText.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == KeyEvent.KEYCODE_ENDCALL) {
valueDialog.getButton(DialogInterface.BUTTON_POSITIVE).callOnClick();
}
return false;
});
}