开启Android学习之旅-6-实战答题App

不经过实战,看再多理论,都是只放在笔记里,活学活用才是硬道理。同时开发应用需要循序渐进,一口气规划300个功能,400张表,会严重打击自己的自信。这里根据所学的,开发一个答题App。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

题库需求分析

  1. 首页显示试卷列表;
  2. 点击试卷,开启计时,逐个显示该试卷的题目;
  3. 点击下一题,检测是否作答,未作答提示,已作答显示下一个,更新进度条显示;
  4. 最后一题,按钮显示“交卷”,作答完成,点击交卷,弹出成绩。

功能分析

  1. 首页试卷列表使用 recyclerview;
  2. 答题页面涉及进度条、卡片视图(cardview)、倒计时(CountDownTimer)
  3. 数据模型:Paper、Question。

开发

开发环境

Android Studio Giraffe | 2022.3.1 Patch 3
Android Gradle Plugin Version 8.1.3
Gradle Version 8.0
JDK 17
compileSdk: 33
targetSdk: 33
minSdk:26

  • 步骤1. 新建项目,这里选择的语言为kotlin。
    解决 gradle 卡顿问题:将 gradle/gradle-wrapper.properties 中的distributionUrl 替换为国内的:
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.0-bin.zip

settings.gradle 国内镜像设置:

pluginManagement {
    repositories {
        maven { url 'https://mirrors.cloud.tencent.com/gradle/'}
        maven {
            url 'https://maven.aliyun.com/repository/google'
        }
        maven {
            url 'https://maven.aliyun.com/repository/jcenter'
        }
        maven {
            url "https://maven.aliyun.com/repository/public"
        }
        maven {
            url 'https://developer.huawei.com/repo/'
        }
        maven {
            url "https://jitpack.io"
        }
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/google'
        }
        maven {
            url 'https://maven.aliyun.com/repository/jcenter'
        }
        maven {
            url "https://maven.aliyun.com/repository/public"
        }
        maven {
            url 'https://developer.huawei.com/repo/'
        }
        maven {
            url "https://jitpack.io"
        }
        google()
        mavenCentral()
    }
}

rootProject.name = "Exam"
include ':app'

开启 viewBinding 在 build.gradle 中添加

buildFeatures {
        viewBinding = true
    }
  • 步骤2:建模型:ExamModel,里面建数据类,PaperModel 和 QuestionModel;
package com.alex.exam

/**
 * @Author      : alex
 * @Date        : on 2024/1/6 16:59.
 * @Description :试卷模型
 */
data class PaperModel(
    val id : String,
    val title : String,
    val subtitle : String,
    val time : String,
    val questionList : List<QuestionModel>
){
    constructor() : this("","","","", emptyList())
}

data class QuestionModel(
    val question : String,
    val options : List<String>,
    val correct : String,
){
    constructor() : this ("", emptyList(),"")
}
  • 步骤3. 主题设置
    配色精美的主题是影响App评价的一个指标,这方面还是专业的人来干。这里只是参考别的,最简设置。
    配置主题色,有利于界面统一,减少在代码中写颜色。在 colors.xml 中先定义主题色、背景配色、操作成功提示配色、操作失败提示配色
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>
    <color name="blue">#1890ff</color>
    <color name="gray">#F4F4F4</color>
    <color name="green">#52C41A</color>
    <color name="red">#FF4D4F</color>
</resources>

再设置主题:

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Base.Theme.Exam" parent="Theme.Material3.DayNight.NoActionBar">
        <!-- Customize your light theme here. -->
        <item name="colorPrimary">@color/blue</item>
    </style>

    <style name="Theme.Exam" parent="Base.Theme.Exam" />
</resources>
  • 步骤4. 首页
    在首页,主要通过RecyclerView展示试卷列表。需要自定义Adapter, 列表项布局,并在 Adapter 中将模型映射到布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_margin="4dp"
    android:elevation="10dp"
    app:cardCornerRadius="24dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:orientation="vertical">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tvPaperTitle"
                tools:text="HTML 测验"
                android:textSize="18sp"
                android:textStyle="bold"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tvPaperSubTitle"
                android:layout_marginTop="4dp"
                tools:text="HTML理论模拟考试"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:orientation="vertical">

            <ImageView
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:src="@drawable/icon_timer"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tvPaperTime"
                tools:text="20 min"/>

        </LinearLayout>

    </RelativeLayout>

</androidx.cardview.widget.CardView>

自定义 PaperListAdapter,给每个试卷项添加点击跳转到答题页面的click事件:

package com.alex.exam

import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.alex.exam.databinding.PaperRecyclerRowBinding

/**
 * @Author      : alex
 * @Date        : on 2024/1/6 17:13.
 * @Description :描述
 */
class PaperListAdapter(private val paperModelList : List<PaperModel>) :
    RecyclerView.Adapter<PaperListAdapter.MyViewHolder>() {
    class MyViewHolder(private val binding: PaperRecyclerRowBinding) : RecyclerView.ViewHolder(binding.root) {
        fun bind(paperModel: PaperModel) {
            binding.apply {
                tvPaperTitle.text = paperModel.title
                tvPaperSubTitle.text = paperModel.subtitle
                tvPaperTime.text = paperModel.time+" min"
                root.setOnClickListener {
                    val intent  = Intent(root.context,ExamActivity::class.java)
                    ExamActivity.questionModelList = paperModel.questionList
                    ExamActivity.time = paperModel.time
                    root.context.startActivity(intent)
                }
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val binding = PaperRecyclerRowBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return MyViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return paperModelList.size
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        holder.bind(paperModelList[position])
    }
}

首页布局中加入RecyclerView控件:

<?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:orientation="vertical"
    android:padding="16dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:src="@drawable/ab" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:background="@drawable/rounded_corner"
        android:backgroundTint="@color/blue"
        android:padding="8dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="学考帮"
            android:gravity="center"
            android:textSize="34sp"
            android:letterSpacing="0.1"
            android:textColor="@color/white"
            android:textStyle="bold"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="知识改变命运,学习成就未来。"
            android:gravity="center"
            android:textSize="18sp"
            android:layout_margin="16dp"
            android:textColor="@color/white"
            android:textStyle="bold"/>

    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="试卷列表"
        android:layout_marginTop="16dp"
        android:layout_marginStart="4dp"
        android:textSize="20sp"
        android:textStyle="bold"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ProgressBar
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_centerInParent="true"
            android:visibility="gone"
            android:id="@+id/progress_bar"/>

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:id="@+id/recycler_view"/>

    </RelativeLayout>

</LinearLayout>

在 MainActivity 中模拟加载数据,加载数据成功前,显示 progressBar,加载后填充到RecyclerView:

package com.alex.exam

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.alex.exam.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding
    private lateinit var paperModelList : MutableList<PaperModel>
    private lateinit var adapter: PaperListAdapter
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        paperModelList = mutableListOf()
        getPapers()
    }

    private fun setupRecyclerView(){
        binding.progressBar.visibility = View.GONE
        adapter = PaperListAdapter(paperModelList)
        binding.recyclerView.layoutManager = LinearLayoutManager(this)
        binding.recyclerView.adapter = adapter
    }

    private fun getPapers(){

        val listQuestionModel = mutableListOf<QuestionModel>()
        listQuestionModel.add(QuestionModel("被称为JAVA之父的是?",
            listOf("Rod Johnson","James Gosling","Marc Fleury","Gavin King"),"James Gosling"))
        listQuestionModel.add(QuestionModel("cmd下编译Java程序使用的命令是( )",
            listOf("java","javav","java -version","javac"),"java"))
        listQuestionModel.add(QuestionModel("byte变量的取值范围是( )",
            listOf("0~65535","-128~127","-256~255","0~32767"),"-128~127"))
        listQuestionModel.add(QuestionModel("Java的前身名字叫( )",
            listOf("Oracle","mysql","spring","OAK"),"OAK"))
        listQuestionModel.add(QuestionModel("( )可将一个java文件转换成一个class文件",
            listOf("调试程序","编译程序","转换器程序","JRE"),"编译程序"))

        val listQuestionModel2 = mutableListOf<QuestionModel>()
        listQuestionModel2.add(QuestionModel("C#语言中,值类型包括:基本值类型、结构类型和( )",
            listOf("小数类型","整数类型","类类型","枚举类型"),"类类型"))
        listQuestionModel2.add(QuestionModel("C#语言中,引用类型包括:类类型、接口类型、数组类型和( )",
            listOf("枚举类型","委托类型","结构类型","小数类型"),"委托类型"))
        listQuestionModel2.add(QuestionModel("C#语言中,( )是一种特殊的类,它只包含数据成员,不包含方法成员",
            listOf("结构类型","枚举类型","接口类型","委托类型"),"结构类型"))
        listQuestionModel2.add(QuestionModel("下列关于抽象类的说法错误的是(  )。",
            listOf("抽象类可以实例化","抽象类可以包含抽象方法","抽象类可以包含抽象属性","抽象类可以引用派生类的实例"),"抽象类可以实例化"))
        listQuestionModel2.add(QuestionModel("下列关于接口的说法错误的是(  )。",
            listOf("接口可以包含方法","接口可以包含属性","接口可以包含事件","接口可以包含索引器"),"接口可以包含方法"))


        paperModelList.add(PaperModel("1","Java","Java语言基础测试题","10",listQuestionModel))
        paperModelList.add(PaperModel("2","C#","C#理论测试题","20",listQuestionModel2))
        paperModelList.add(PaperModel("3","JavaScript","JavaScript自测试题","15",listQuestionModel))
        setupRecyclerView()
    }
}
  • 步骤5. 答题页
    答题页面布局,显示题号进度条、倒计时、题目、下一题按钮;同时在交卷时,需要弹出对话框,这里要自定义。
    自定义对话框:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:gravity="center"
    android:padding="16dp"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:text="恭喜你通过考试!"
        android:gravity="center"
        android:textSize="20sp"
        android:textStyle="bold"
        android:id="@+id/tvScoreTitle"/>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <com.google.android.material.progressindicator.CircularProgressIndicator
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/circlePgrScoreProgress"
            android:layout_centerVertical="true"
            app:trackColor="@color/gray"
            tools:progress="60"
            app:trackCornerRadius="20dp"
            app:trackThickness="8dp"
            app:indicatorSize="90dp"/>

        <TextView
            android:id="@+id/tvProgress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textSize="18sp"
            android:textStyle="bold"
            tools:text="50%" />
    </RelativeLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:text="答题情况:6 / 10"
        android:gravity="center"
        android:id="@+id/tvScoreSubTitle"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="确定"
        android:layout_margin="8dp"
        android:id="@+id/btnFinish"/>

</LinearLayout>

答题页面布局:

<?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:orientation="vertical"
    android:padding="16dp"
    tools:context=".ExamActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:text="题号 7/20"
            android:textSize="18sp"
            android:textStyle="bold"
            android:layout_centerVertical="true"
            android:id="@+id/question_indicator_textview"/>

        <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:src="@drawable/icon_timer"
            app:tint="@color/blue"
            android:layout_marginEnd="4dp"
            android:layout_toStartOf="@id/timer_indicator_textview"
            android:layout_centerVertical="true"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:text="5:46"
            android:textSize="18sp"
            android:textStyle="bold"
            android:textColor="@color/blue"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:id="@+id/timer_indicator_textview"/>
    </RelativeLayout>

    <com.google.android.material.progressindicator.LinearProgressIndicator
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginVertical="8dp"
        tools:progress="40"
        android:id="@+id/question_progress_indicator"/>

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginVertical="8dp"
        android:elevation="4dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="16dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="120dp"
                tools:text="这里是题目"
                android:textSize="20sp"
                android:textStyle="bold"
                android:padding="8dp"
                android:background="@drawable/rounded_corner"
                android:backgroundTint="@color/blue"
                android:textColor="@color/white"
                android:gravity="center"
                android:layout_marginVertical="8dp"
                android:id="@+id/question_textview"/>
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginVertical="4dp"
                android:backgroundTint="@color/gray"
                tools:text="答案 A"
                android:textColor="@color/black"
                android:paddingVertical="12dp"
                android:gravity="center_vertical"
                android:textSize="18sp"
                android:id="@+id/btnA" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginVertical="4dp"
                android:backgroundTint="@color/gray"
                tools:text="答案 B"
                android:textColor="@color/black"
                android:paddingVertical="12dp"
                android:gravity="center_vertical"
                android:textSize="18sp"
                android:id="@+id/btnB" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginVertical="4dp"
                android:backgroundTint="@color/gray"
                tools:text="答案 C"
                android:textColor="@color/black"
                android:paddingVertical="12dp"
                android:gravity="center_vertical"
                android:textSize="18sp"
                android:id="@+id/btnC" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginVertical="4dp"
                android:backgroundTint="@color/gray"
                tools:text="答案 D"
                android:textColor="@color/black"
                android:paddingVertical="12dp"
                android:gravity="center_vertical"
                android:textSize="18sp"
                android:id="@+id/btnD" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginVertical="4dp"
                android:text="下一题"
                android:paddingVertical="12dp"
                android:gravity="center_vertical"
                android:layout_gravity="end"
                android:textSize="20sp"
                android:paddingHorizontal="40dp"
                android:id="@+id/btnNext" />

        </LinearLayout>

    </androidx.cardview.widget.CardView>

</LinearLayout>

ExamActity 定义了试题列表,是从上个界面传过来的数据;首先初始化数据,包括加载第一个题目内容,设置进度条、题号、开始计时;再点击下一题时,切换题目,如果是到最后一题,则显示交卷按钮,如果最后一题作答完成,并点击交卷,则停止计时,显示成绩弹窗,确认弹窗后 ,停止计时,并销毁,退出答题页。

package com.alex.exam

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.CountDownTimer
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import com.alex.exam.databinding.ActivityExamBinding
import com.alex.exam.databinding.ScoreDialogBinding

class ExamActivity : AppCompatActivity(), View.OnClickListener {

    private var timer : CountDownTimer? = null
    companion object {
        var questionModelList : List<QuestionModel> = listOf()
        var time : String = ""
    }

    lateinit var binding: ActivityExamBinding

    private var currentQuestionIndex = 0;
    private var selectedAnswer = ""
    private var score = 0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityExamBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.apply {
            btnA.setOnClickListener(this@ExamActivity)
            btnB.setOnClickListener(this@ExamActivity)
            btnC.setOnClickListener(this@ExamActivity)
            btnD.setOnClickListener(this@ExamActivity)
            btnNext.setOnClickListener(this@ExamActivity)
        }

        loadQuestions()
        startTimer()
    }

    private fun startTimer() {
        val totalTimeInMillis = time.toInt() * 60 * 1000L
        timer = object : CountDownTimer(totalTimeInMillis,1000L){
            override fun onTick(millisUntilFinished: Long) {
                val seconds = millisUntilFinished /1000
                val minutes = seconds/60
                val remainingSeconds = seconds % 60
                binding.timerIndicatorTextview.text = String.format("%02d:%02d", minutes,remainingSeconds)
            }

            override fun onFinish() {
                // 结束考试
                finishQuiz()
            }

        }.start()
    }

    // 加载试卷中的题目
    private fun loadQuestions(){
        selectedAnswer = ""
        // 判断是否是最后一题,如果是最后一题,点击下一题按钮,直接交卷,设置进度条为100%
        if(currentQuestionIndex == questionModelList.size){
            binding.questionProgressIndicator.progress = 100
            timer?.cancel()
            finishQuiz()
            return
        }
        // 加载题目内容到界面
        binding.apply {
            questionIndicatorTextview.text = "题号 ${currentQuestionIndex+1}/ ${questionModelList.size} "
            questionProgressIndicator.progress =
                ( currentQuestionIndex.toFloat() / questionModelList.size.toFloat() * 100 ).toInt()
            questionTextview.text = questionModelList[currentQuestionIndex].question
            btnA.text = questionModelList[currentQuestionIndex].options[0]
            btnB.text = questionModelList[currentQuestionIndex].options[1]
            btnC.text = questionModelList[currentQuestionIndex].options[2]
            btnD.text = questionModelList[currentQuestionIndex].options[3]
        }

    }

    // 结束考试
    private fun finishQuiz() {
        val totalQuestions = questionModelList.size
        val percentage = ((score.toFloat() / totalQuestions.toFloat() ) *100 ).toInt()

        // 弹出对话框,显示考试结果
        val dialogBinding  = ScoreDialogBinding.inflate(layoutInflater)
        dialogBinding.apply {
            circlePgrScoreProgress.progress = percentage
            tvProgress.text = "$percentage %"
            if(percentage>60){
                tvScoreTitle.text = "恭喜你通过考试!"
                tvScoreTitle.setTextColor(getColor(R.color.green))
            }else{
                tvScoreTitle.text = "未及格,加油哦!"
                tvScoreTitle.setTextColor(getColor(R.color.red))
            }
            tvScoreSubTitle.text = "答对:$score / $totalQuestions"
            btnFinish.setOnClickListener {
                finish()
            }
        }

        AlertDialog.Builder(this)
            .setView(dialogBinding.root)
            .setCancelable(false)
            .show()
    }

    override fun onClick(view: View?) {
        binding.apply {
            //初始化选项按钮,背景颜色位灰色,文字颜色未黑色
            btnA.setBackgroundColor(getColor(R.color.gray))
            btnB.setBackgroundColor(getColor(R.color.gray))
            btnC.setBackgroundColor(getColor(R.color.gray))
            btnD.setBackgroundColor(getColor(R.color.gray))

            btnA.setTextColor(getColor(R.color.black))
            btnB.setTextColor(getColor(R.color.black))
            btnC.setTextColor(getColor(R.color.black))
            btnD.setTextColor(getColor(R.color.black))

        }

        val clickedBtn = view as Button
        if(clickedBtn.id==R.id.btnNext){
            // 点击下一题
            if(selectedAnswer.isEmpty()){
                Toast.makeText(applicationContext,"请选择答案",Toast.LENGTH_SHORT).show()
                return;
            }
            // 判断答案是否正确
            if(selectedAnswer == questionModelList[currentQuestionIndex].correct){
                score++
                Log.i("考试分数",score.toString())
            }
            currentQuestionIndex++

            // 判断是否是最后一题
            if(currentQuestionIndex == questionModelList.size-1){
             binding.btnNext.text = "交卷"
            }

            loadQuestions()
        }else{
            // 选中答案,改变背景颜色和文字颜色
            selectedAnswer = clickedBtn.text.toString()
            clickedBtn.setBackgroundColor(getColor(R.color.blue))
            clickedBtn.setTextColor(Color.WHITE)
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        //取消计时器
        timer?.cancel()
        timer = null
    }
}

打包

打包前,先定义个logo, 在 new->Image Asset,设置个图片:
在这里插入图片描述
最后点击 build -> Generate Signed Bundle or APK, 加载 jks 打包密钥,进行apk 打包
在这里插入图片描述

夜神模拟器图标无效问题
打包后在模拟器上运行,发现图标还是小机器人,最后排查时 minSdk 对应的android 版本大于 模拟器的版本,将 minSdk降低到 25,再重新打包,就可以啦。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/305855.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

公司新买的BI,和金蝶系统配合太默契了

公司一直都用金蝶系统来实现包括财务管理、供应链管理、人力资源管理等多个方面的资源的合理配置和业务流程的自动化。但到了数据分析这块&#xff0c;金蝶系统就明显力不从心&#xff0c;需要一个专业的数据分析工具来接手。财务经理推荐用奥威BI&#xff0c;说这款BI的一大特…

光纤知识总结

1光纤概念&#xff1a; 光导纤维&#xff08;英语&#xff1a;Optical fiber&#xff09;&#xff0c;简称光纤&#xff0c;是一种由玻璃或塑料制成的纤维&#xff0c;利用光在这些纤维中以全内反射原理传输的光传导工具。 微细的光纤封装在塑料护套中&#xff0c;使得它能够…

OpenAI ChatGPT-4开发笔记2024-01:开发环境

ChatGPT发展一日千里。工具、函数少则数日&#xff0c;多则数月就加入了Deprecated行列不再如预期般工作。元旦闲来无事&#xff0c;用最新的ChatGPT重写一下各种开发场景&#xff0c;全部实测通过。 开发环境&#xff1a; 电脑&#xff1a;两台笔记本&#xff1a;HP和MacBoo…

Pixi.js的魅力

摘要&#xff1a;官网 Web开发的时代&#xff0c;图形和动画已经成为了吸引用户注意力的重要手段之一。而 Pixi.js 作为一款高效、易用的2D渲染引擎&#xff0c;已经成为了许多开发者的首选~~ 项目中&#xff0c;有一些图像的处理操作&#xff08;3D图&#xff0c;2D图都有&…

49寸OLED拼接屏:技术、应用与市场前景

作为“49寸OLED拼接屏”技术总监&#xff0c;我深知这一产品对于显示行业的重要性。随着显示技术的不断进步&#xff0c;OLED拼接屏在高端显示市场占据了一席之地。下面&#xff0c;我将从技术的角度深入剖析这一产品。 一、参数 49寸OLED拼接屏是一款高端大屏显示产品&#x…

在线文本转语音工具的实现

文章目录 文章最下面有工具链接&#xff01;前言edge-tts库1.首先使用pip安装这个库2.写一段示例代码3.多线程 pydub库1.介绍2.示例 将他们整合起来我把他们部署到了我的服务器上&#xff0c;可以在线使用点我使用工具 文章最下面有工具链接&#xff01; 前言 最近有文字转语…

Halcon3D篇-3D预处理,滤波,点云筛选

前言 由于3D相机采集到的数据通常通过Tiff格式的深度图进行显示或者保存。 深度图与模型的互转可以访问另一篇博客&#xff1a;https://blog.csdn.net/m0_51559565/article/details/135362674 关于3D相机的数据采集&#xff0c;可以访问我们另一篇关于LMI3D相机SDK的二次开发…

Redis主从复制哨兵及集群

目录 一.主从复制 主从复制的工作原理如下&#xff1a; 主从复制的作用&#xff1a; 搭建Redis 主从复制 每台服务器配置&#xff1a; ​编辑进行编译安装&#xff1a; 定义systemd服务管理脚本&#xff1a; 开启服务&#xff0c;报错看下内容&#xff1a; 修改 Redis…

Hyperledger Fabric 二进制安装部署 Peer 节点

规划网络拓扑 3 个 orderer 节点&#xff1b;组织 org1 , org1 下有两个 peer 节点&#xff0c; peer0 和 peer1; 组织 org2 , org2 下有两个 peer 节点&#xff0c; peer0 和 peer1; 节点宿主机 IPhosts端口cli192.168.1.66N/AN/Aorderer0192.168.1.66orderer0.example.com70…

深入浅出:原生态App封装的艺术

一、原生态App封装的优势 性能的极致&#xff1a;原生App直接调用设备的硬件资源&#xff0c;减少了中间层的干扰&#xff0c;从而实现更快的运行速度和更流畅的动画效果。 2. 用户体验的完美&#xff1a;原生App可以访问并遵循特定平台的设计指南&#xff0c;提供与操作系统无…

C#: Label、TextBox 鼠标停留时显示提示信息

说明&#xff1a;记录在 Label、TextBox 控件上 鼠标停留时显示提示信息的方法。 1.效果图 2.具体实现步骤 1. 在Form 窗口中先创建 Label 并取名&#xff1a;KEY_label &#xff0c;或 TextBox 取名&#xff1a;KEY_textBox 2. lable控件的 tips 实现方法1 &#xff1a;代码…

519基于单片机的自动切割流程控制系统

基于单片机的自动切割流程控制系统[proteus仿真] 自动切割流程控制系统这个题目算是课程设计和毕业设计中常见的题目了&#xff0c;本期是一个基于单片机的自动切割流程控制系统 需要的源文件和程序的小伙伴可以关注公众号【阿目分享嵌入式】&#xff0c;赞赏任意文章 2&…

Centos7 手动更改系统时间

文章目录 1.更改系统时间2.写入系统时间3.查看是否写入成功 1.更改系统时间 date -s "2017-12-18 09:40:00"2.写入系统时间 hwclock -w3.查看是否写入成功 timedatectl

MongoDB重写

可重写操作 当与数据库网络出现连接问题或在数据库集群主节点切换时不能找到一个正在工作的主节点时&#xff0c;可重试写允许数据库连接驱动再进行一次数据库写入操作。 前置条件 需要复制集或分片集&#xff0c;不支持单节点数据库可重试写需要存储引擎支持文档级别锁定&a…

deeplabv3模型的关键点

spp空间金字塔&#xff1a;可以避免图片固定输入&#xff0c;resize之后又减少了语义信息。这样任意大小的图片都可以输入&#xff0c;就保存了完整的信息。 空洞卷积&#xff1a;卷积的升级&#xff0c;多个尺寸的卷积核&#xff0c;增大了感受野&#xff0c;语义信息更加丰…

接口自动化测试要做什么?

作者&#xff1a;不辣的皮皮 链接&#xff1a;https://www.zhihu.com/question/384727359/answer/1124441469 来源&#xff1a;知乎 著作权归作者所有。商业转载请联系作者获得授权&#xff0c;非商业转载请注明出处。 可以分为四个步骤/阶段。 原理 》 业务逻辑》 工具》 …

【LeetCode】2626. 数组归约运算

数组归约运算 题目题解 题目 给定一个整数数组 nums、一个 reducer 函数 fn 和一个初始值 init&#xff0c;返回通过依次对数组的每个元素执行 fn 函数得到的最终结果。 通过以下操作实现这个结果&#xff1a;val fn(init, nums[0])&#xff0c;val fn(val, nums[1])&#…

机器学习-线性回归实践

目标&#xff1a;使用Sklearn、numpy模块实现展现数据预处理、线性拟合、得到拟合模型&#xff0c;展现预测值与目标值&#xff0c;展现梯度下降&#xff1b; 一、导入模块 import numpy as np np.set_printoptions(precision2) from sklearn.linear_model import LinearRegr…

JavaWeb的Filter详解

一、Filter过滤器简介 1、基本概念 JavaWeb的三大组件之一&#xff0c;三大组件为&#xff1a;Servlet、Filter、Listener。 过滤器相当于浏览器与Web资源之间的一道过滤网&#xff0c;在访问资源之前通过一系列的过滤器对请求 进行修改、判断以及拦截等&#xff0c;也可以对…

CMake入门教程【核心篇】导入外部库Opencv

😈「CSDN主页」:传送门 😈「Bilibil首页」:传送门 😈「动动你的小手」:点赞👍收藏⭐️评论📝 文章目录 环境准备示例:在Windows上配置OpenCV路径示例:在Linux上配置OpenCV路径环境准备 首先确保你的系统中安装了CMake。可以通过以下命令安装: Windows: 下载并…
最新文章