Dil*_*lip 12 android dialog webview
我已经Dialog在我的Andorid 应用程序中用于显示广告.但是我必须显示这个Dialog大约50dp来自buttom的顶部所以我认为我们应该设置DialogGravity buttom并设置它的buttom边距50dp.但我不能使用保证金.所以Dialog请建议我如何解决这个问题.
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_element"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dialogback"
android:orientation="vertical" >
<WebView
android:id="@+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Java的:
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
LayoutInflater inflator = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.ad, null, false);
dialog.setContentView(view);
dialog.getWindow().setGravity(Gravity.BOTTOM);
dialog.setCancelable(true);
WebView webView = (WebView) dialog.findViewById(R.id.webView);
webView.loadUrl("");
webView.setWebViewClient(new MyWebViewClient());
webView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
dialog.show();
Run Code Online (Sandbox Code Playgroud)
Nam*_*ung 19
我做了类似的笑脸对话.我扩展了对话框
public class SmileCustomDialog extends Dialog {
Context mcontext;
GridView mGridview;
public GridView getGridview() {
return mGridview;
}
public SmileCustomDialog(final Context context) {
super(context, R.style.SlideFromBottomDialog);
this.mcontext = context;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.emocategorydialog, null);
mGridview = (GridView) v.findViewById(R.id.emogrid);
mGridview.setSelector(new ColorDrawable(Color.TRANSPARENT));
ImageAdapter mAdapter = new ImageAdapter(mcontext);
mGridview.setAdapter(mAdapter);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(v);
WindowManager.LayoutParams params = this.getWindow().getAttributes();
this.setCanceledOnTouchOutside(true);
params.y = -100;
this.getWindow().setAttributes(params);
}
}
Run Code Online (Sandbox Code Playgroud)
但至关重要的是
WindowManager.LayoutParams params = yourDialog.getWindow().getAttributes(); // change this to your dialog.
params.y = -100; // Here is the param to set your dialog position. Same with params.x
yourDialog.getWindow().setAttributes(params);
Run Code Online (Sandbox Code Playgroud)
只需在显示对话框之前添加它.
小智 15
WindowManager.LayoutParams:
public int x:X position ...当使用LEFT或START或RIGHT或END时,它提供偏离给定边的
公共内容y:Y位置...当使用TOP或BOTTOM时,它提供偏移量给定边缘
(http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#x)
因此:
final Dialog dialog = new Dialog(context);
// ...
// e.g. top + right margins:
dialog.getWindow().setGravity(Gravity.TOP|Gravity.RIGHT);
WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes();
layoutParams.x = 100; // right margin
layoutParams.y = 170; // top margin
dialog.getWindow().setAttributes(layoutParams);
// e.g. bottom + left margins:
dialog.getWindow().setGravity(Gravity.BOTTOM|Gravity.LEFT);
WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes();
layoutParams.x = 100; // left margin
layoutParams.y = 170; // bottom margin
dialog.getWindow().setAttributes(layoutParams);
// etc.
Run Code Online (Sandbox Code Playgroud)
小智 7
您可以为对话框创建样式并在其中放置边距。
例如:
<style name="custom_style_dialog">
<item name="android:layout_marginStart">16dp</item>
<item name="android:layout_marginEnd">16dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后,在您的对话框类中:
class CountryDialog(
context: Context
) : Dialog(context, R.style.custom_style_dialog) {
//your code here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42892 次 |
| 最近记录: |