团队冲刺第六天
今天对新闻的详细页面进行设计,在编写新闻界面的布局时,其实还是有些头疼的,
因为使用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);
}
}

浙公网安备 33010602011771号