第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

如何實現(xiàn)一個簡單的點擊增加積分再升級的功能

標(biāo)簽:
Java Android

https://img1.sycdn.imooc.com//5fac36e60001ca9503680358.jpg

Layout:

<?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:gravity="center"
    android:background="#00BFFF"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Level"
            android:textSize="30dp"
            android:textColor="#ffffff"/>
        <TextView
            android:id="@+id/level_num"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ffffff"
            android:textSize="30dp"
            android:layout_marginLeft="10dp"
            android:text="1"/>


    </LinearLayout>

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:gravity="center"
       android:layout_margin="10dp"
       android:orientation="horizontal">
       <TextView
           android:id="@+id/txt"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="0"
           android:layout_margin="10dp"
           android:textColor="#ffffff"
           android:textSize="20dp"/>
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="/"
           android:layout_margin="10dp"
           android:textSize="20dp"
           android:textColor="#ffffff"/>
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:textColor="#ffffff"
           android:layout_margin="10dp"
           android:textSize="20dp"
           android:text="10"/>
   </LinearLayout>
    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        app:cardCornerRadius="10dp"
        android:layout_height="wrap_content">
    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="200dp"
        android:layout_height="10dp"
        android:max="100"
        android:min="10"
        android:secondaryProgress="70"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        android:layout_marginTop="10dp"/>
    </androidx.cardview.widget.CardView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:orientation="horizontal">
        <Button
            android:id="@+id/start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000"
            android:textSize="15dp"
            android:layout_margin="10dp"
            android:text="开始"/>

    </LinearLayout>



</LinearLayout>

MainActivity

package com.example.userrecyclerviewapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;


import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity {
  private TextView txt,level_num;
  private ProgressBar pb;
  private Button start;
  private int level = 1 ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        level_num = findViewById(R.id.level_num);
        txt = findViewById(R.id.txt);
        pb = findViewById(R.id.progressBar);
        start = findViewById(R.id.start);
        pb.getProgressDrawable().setColorFilter(Color.YELLOW,android.graphics.PorterDuff.Mode.SRC_IN);
        initEvent();

    }

    private void initEvent() {
    start.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int progress = pb.getProgress();
            int real_num = progress/10;


            if(real_num <10){
                progress = progress+10;
                txt.setText(String.valueOf(real_num));
                pb.setProgress(progress);
            }else {
                pb.setProgress(0);
                txt.setText("0");
                level++;
                level_num.setText(String.valueOf(level));

            }

        }
    });

}

}


點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消