zoukankan      html  css  js  c++  java
  • 团队冲刺第六天

    今天对新闻的详细页面进行设计,在编写新闻界面的布局时,其实还是有些头疼的,

    因为使用Textview的话,新闻会堆在一起,所以需要使用webview,而是用webview也不能都将爬取的新闻数据

    源码都爬取过来,所以需要只爬取新闻的内容部分,因此爬取新闻的代码也是进行了更改,将新闻内容部分那些源码爬取

    下来在webview中使用。

    主要代码:

    package com.example.bowenwang;
    
    import androidx.annotation.RequiresApi;
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.content.Intent;
    import android.graphics.Color;
    import android.os.Build;
    import android.os.Bundle;
    import android.view.View;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.widget.TextView;
    
    public class DetailActivity extends AppCompatActivity {
        TextView title;
        TextView time;
        TextView place;
        TextView author;
        WebView web;
        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_detail);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            StatusBarCompat.compat(this, Color.parseColor("#FFFFFFFF"));
            initview();
        }
        private void initview() {
            title=findViewById(R.id.datail_title);
            time=findViewById(R.id.datail_time);
            place=findViewById(R.id.datail_place);
            author=findViewById(R.id.datail_author);
            web=findViewById(R.id.web);
            Intent intent = this.getIntent();
            Bean bean=(Bean) intent.getSerializableExtra("bean");
            title.setText(bean.getTitle());
            time.setText(bean.getTime());
            place.setText(bean.getPlace());
            author.setText(bean.getAuthor());
            String data=bean.getContent();
            web.getSettings().setJavaScriptEnabled(true);//启用js
            web.getSettings().setBlockNetworkImage(false);//解决图片不显示
            web.getSettings().setDomStorageEnabled(true);
            if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
                web.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
            }
            web.loadDataWithBaseURL("about:blank",data,"text/html","utf-8",null);
        }
    }
    
    作者:哦心有
    本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    strncpy (Strings) – C 中文开发手册
    HTML track label 属性
    Java面试题:常用的Web服务器有哪些?
    鲲鹏920上安装ovs
    基于AC控制器+VXLAN解决方案
    二层MAC学习及BUM报文转发
    基于mac表的vxlan转发
    Agile Controller vxlan
    设置鲲鹏916/920通过pxe安装os
    ovs-vxlan&vlan
  • 原文地址:https://www.cnblogs.com/haobox/p/14880176.html
Copyright © 2011-2022 走看看