问题:
假设:
次要详情:
EditText具有以下类型:
AlertDialog的高度/宽度以像素为单位,通过密度缩放(请参阅代码);
困惑:
守则:
private void show_activation_prompt()
{
// =============================================================
// ======== create EditText which filters text =================
// =============================================================
// filter for alphanumerics, insert dashes during entry, capitalize, and turn off suggestions
final TextWatcher textEditorWatcher = new SafeTextWatcher(); //custom
final LayoutParams lparams = new LayoutParams(100,100);
final EditText edittext= new EditTextPersist(mContext);
edittext.addTextChangedListener(textEditorWatcher);
edittext.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS |
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
);
edittext.setLayoutParams(lparams);
//edittext.setEms(10); //doesn't work either
// =============================================================
// ======== create alert dlg, set btn callbacks ================
// =============================================================
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setPositiveButton("Upgrade", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
String activationKey = edittext.getText().toString();
on_key_entered(activationKey);
}
} );
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton)
{
post_activation_result(QlmLicense.ACTIVATION_INVALID);
}
} );
// =============================================================
// ======== configure the AlertDialog/EditText =================
// =============================================================
int nWidth, nHeight;
final float scale = mContext.getResources().getDisplayMetrics().density;
nWidth = (int) (900 * scale + 0.5f);
nHeight = (int) (500 * scale + 0.5f);
builder.setView(edittext)
.setMessage("Enter an Activation Key:")
.setTitle("Upgrade From Trial Version")
.setCancelable(false)
.show()
.getWindow()
.setLayout(nWidth,nHeight);
}
答案 0 :(得分:3)
我的问题很简单,只需将LayoutParams
Edittext
AlertDialog
LayoutParams
改为FrameLayout.LayoutParams
,edittext.setLayoutParams(lparams);
改为dialog.show()
,然后致电AlertDialog.Builder builder = new AlertDialog.Builder(this);
int nWidth, nHeight;
final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
nWidth = (int) (900 * scale + 0.5f);
nHeight = (int) (500 * scale + 0.5f);
final FrameLayout.LayoutParams lparams = new FrameLayout.LayoutParams(100,100);
final EditText edittext= new EditText(this);
//edittext.addTextChangedListener(textEditorWatcher);
edittext.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS |
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
);
// =============================================================
// ======== create alert dlg, set btn callbacks ================
// =============================================================
builder.setPositiveButton("Upgrade", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
String activationKey = edittext.getText().toString();
//on_key_entered(activationKey);
Toast.makeText(getApplicationContext(), activationKey, Toast.LENGTH_LONG).show();
}
} );
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//post_activation_result(QlmLicense.ACTIVATION_INVALID);
}
});
builder.setView(edittext)
.setMessage("Enter an Activation Key:")
.setTitle("Upgrade From Trial Version")
.setCancelable(false)
.show()
.getWindow()
.setLayout(nWidth, nHeight);
//Change setLayoutParams to here
edittext.setLayoutParams(lparams);
致电ccInner
:
isInIframe