直播平台开发,加载网页、html文件显示加载进度

发布时间 2023-11-23 14:13:40作者: 云豹科技-苏凌霄

直播平台开发,加载网页、html文件显示加载进度

一、视图绑定

通过视图绑定功能,您可以更轻松地编写可与视图交互的代码。在模块中启用视图绑定之后,系统会为该模块中的每个 XML 布局文件生成一个绑定类。绑定类的实例包含对在相应布局中具有 ID 的所有视图的直接引用。

 

在大多数情况下,视图绑定会替代 findViewById。

 

视图绑定功能可按模块启用。要在某个模块中启用视图绑定,请将 viewBinding 元素添加到其 build.gradle 文件中,如下例所示:

 


    viewBinding {
        enabled = true
    }
 

二、新建加载WebViewActivity

新建WebViewActivity加载网页html文件

 


class WebViewActivity : AppCompatActivity() {
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }
}

 

 

页面xml文件activity_web_view如下:

 


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <WebView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="@null"
        android:indeterminateOnly="false"
        android:max="100"
        app:layout_constraintTop_toTopOf="parent"
        android:progressDrawable="@drawable/progress_bar_horizontal"/>
</androidx.constraintlayout.widget.ConstraintLayout>
 

 

进度条progress_bar_horizontal.xml样式如下:

 


<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@android:id/background"
        android:drawable="@color/white"/>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <gradient
                    android:angle="270"
                    android:centerColor="#00923F"
                    android:centerY="0.75"
                    android:endColor="#888C98"
                    android:startColor="#00923F" />
            </shape>
        </clip>
    </item>
</layer-list>

 

 以上就是 直播平台开发,加载网页、html文件显示加载进度,更多内容欢迎关注之后的文章