如何以编程方式创建透明活动?(How to create a transparent Activity programmatically?)

编程入门 行业动态 更新时间:2024-10-26 18:28:53
如何以编程方式创建透明活动?(How to create a transparent Activity programmatically?)

我想使用webView作为当前Activity的内容启动一个Activity。 这项新活动需要透明,webview应该是中心。 我环顾网络,但只有我找到的解决方案是使用样式xmls。 我想使用纯代码,即没有xml声明。 如果有人遇到过这个,那么请说清楚。

I want to launch an Activity with a webView as its content from current Activity. This new activity needs to be transparent and webview should be in the center. I looked around the web but only solutions I found were using style xmls. I want to do it using pure code i.e. no xml declarations. if anybody has come across this then please shed some light.

最满意答案

您是否考虑过在其中嵌入WebView创建一个Dialog?

编辑这是我在onCreateDialog() :

Dialog d = new Dialog(MainFloatOver.this); LinearLayout mLinearLayout = new LinearLayout(this); mLinearLayout.setBackgroundColor(android.R.color.transparent); LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); mLinearLayout.setLayoutParams(llp); d.setContentView(mLinearLayout); WebView mWebView = new WebView(this); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl("www.google.com"); mLinearLayout.addView(mWebView);

Have you considered creating a Dialog with a WebView embedded in it?

EDIT Here is what I have in my onCreateDialog() :

Dialog d = new Dialog(MainFloatOver.this); LinearLayout mLinearLayout = new LinearLayout(this); mLinearLayout.setBackgroundColor(android.R.color.transparent); LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); mLinearLayout.setLayoutParams(llp); d.setContentView(mLinearLayout); WebView mWebView = new WebView(this); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl("www.google.com"); mLinearLayout.addView(mWebView);

更多推荐

本文发布于:2023-07-26 08:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1272900.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:透明   方式   create   programmatically   Activity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!