• 团队冲刺第六天


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

    因为使用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);
        }
    }
    
    作者:哦心有
    本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    CSS边框,背景,边距,溢出
    数字电子技术课程设计之基于触发器的三位二进制同步减法计数器无效态000/110
    集成电路版图与工艺课程设计之用CMOS实现Y=AB+C电路与版图
    金属磁记忆传感器封装
    基于FPGA 的8b10b编解码电路前端电路设计
    Css颜色和文本字体
    Css中的选择器
    Css基本语法及页面引用
    65 插入排序
    63 散列表的查找
  • 原文地址:https://www.cnblogs.com/haobox/p/14880176.html
Copyright © 2020-2023  润新知