WebView设置透明,滚动时有黑影,加载图片
2017-08-01 11:10
423 查看
解决黑影的关键代码:android:layerType=”software”
展示数据与透明
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/p_bg" android:orientation="vertical"> <include layout="@layout/common_header"/> <TextView android:id="@+id/tv_news_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="100dp" android:layout_marginRight="100dp" android:gravity="center" android:layout_margin="10dp" android:textColor="@android:color/white" android:visibility="gone" android:textSize="25sp" /> <WebView android:id="@+id/wv" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:layout_marginLeft="50dp" android:layout_marginRight="50dp" android:layerType="software" /> </LinearLayout>
展示数据与透明
public class HtmlActivity extends BaseActivity { public static final String EXTRA_CONTENT = "extra_content"; public static final String EXTRA_TITLE = "extra_title"; public final static String CSS_STYLE ="<style>* {color:#fff} </style>"; private WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_html); mWebView = findViewById(R.id.wv); ((TextView)findViewById(R.id.tv_news_title)).setText(getIntent().getStringExtra(EXTRA_TITLE)); WebSettings settings = mWebView.getSettings(); // settings.setJavaScriptEnabled(true); settings.setBlockNetworkImage(false);//不阻塞网络图片 if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP) { //5.0以后 https 图片地址,加这个 settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } mWebView.loadDataWithBaseURL(null,CSS_STYLE+getIntent().getStringExtra(EXTRA_CONTENT), "text/html", "utf-8",null); mWebView.setBackgroundColor(Color.TRANSPARENT); } }
相关文章推荐
- WebView设置透明和设置背景图片的方法
- 利用webView实现加载网络图片居中并适应手机屏幕,以及img设置前缀
- WebView设置透明和设置背景图片的方法
- android WebView加载html 并 引用本地资源(图片、字体库)
- Android webview加载https网页时http图片无法显示
- UI一揽子计划 21 (UICollectionView、SDWebImage第三方类库加载图片的使用、集合视图的布局UICollectionViewFlowLayout 、自定义Cell、布局协议
- (Andr 4000 oid学习)ImageView设置异步加载的网络图片
- Android WebView加载html文本时,图片太大不能适配屏幕
- Android - webview拦截css,js,图片后加载本地外部存储的文件(shouldOverrideUrlLoading)
- WebViewDialog默认背景透明的加载网页的对话框, 红包、活动弹窗
- WebView加载网页不显示图片解决办法
- WebView加载图片超过屏幕大小的问题
- 设置WebView接受所有网站的证书加载https
- android webview 加载本地图片
- Xamarin.ios 使用webview加载gif图片
- webview加载https页面图片不能显示问题
- 设置Webview的滚动条属性- 滚动条白边解决方法
- tableView使用SDWebImage加载图片时滚动优化
- android 基于HTTPSWebview无法正常加载图片