我想在左侧和右侧边距添加Android警报对话框,让我们说15%的屏幕宽度,这是我的代码到目前为止,我该怎么做?
AlertDialog.Builder alert = new AlertDialog.Builder(context);
WebView wv = new WebView(context);
wv.setBackgroundColor(getResources().getColor(android.R.color.transparent));
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
wv.loadUrl(ANY_URL_STRING);
alert.setView(wv);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
alert.show();
答案 0 :(得分:0)
为您的aleart对话框创建自定义布局,并在xml中提供边距。
LayoutInflater li = LayoutInflater.from(class.this);
View promptsView = li.inflate(R.layout.custom_layout, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
class.this);
alertDialogBuilder.setView(promptsView);
final WebView wv= (WebView) promptsView.findViewById(R.id.webview);
// create alert dialog
alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});