我有一个AlertDialog,它提示用户在EditText中输入文本,但是AlertDialog弹出窗口的宽度不如我所需要。看起来是这样的:
我如何扩大范围?
这是我代码的相关部分:
AlertDialog.Builder alert = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustom);
// Using the following constructor produces a desirable width but
// the wrong theme colors
// AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
final EditText edittext = new EditText(getContext());
alert.setMessage("Enter Your Message");
alert.setTitle("Enter Your Title");
alert.setView(edittext);
alert.setPositiveButton("Yes Option", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String YouEditTextValue = edittext.getText().toString();
}
});
alert.setNegativeButton("No Option", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// what ever you want to do with No option.
}
});
alert.show();
我尝试主题:
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog">
<item name="android:textColor">@color/colorLightGray</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">10sp</item>
<item name="android:windowBackground">@color/colorDarkerGray</item>
</style>
答案 0 :(得分:0)
根据需要设置自定义的Windowmanager布局参数,您应该一切顺利。在调用对话框的show()
之后执行此操作,例如:
alertDialog.show();
WindowManager.LayoutParams layoutParams = new
WindowManager.LayoutParams();
layoutParams .copyFrom(alertDialog.getWindow().getAttributes());
layoutParams .width = 150;
layoutParams .height = 500;
layoutParams .x=-170;
layoutParams .y=100;
alertDialog.getWindow().setAttributes(layoutParams );
答案 1 :(得分:0)
尝试一下
4/10/2018