如何在安卓中写用UI美化实现的进度条


如何使用UI美化写进度条


具体实现的代码如下:


我们的Java文件:



import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.wls.tiaotiaotang.TiaoProgress;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TiaoProgress tiaoProgress;
    private int pro;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tiaoProgress= (TiaoProgress) this.findViewById(R.id.sss);
        tiaoProgress.setCircleColor(Color.GREEN);
        tiaoProgress.setArrowColor(Color.RED);
        tiaoProgress.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        if (!tiaoProgress.isDownloading()) {
            pro=0;
            tiaoProgress.startDownload();
            handler.sendMessageDelayed(Message.obtain(),200);
        }
    }
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if (pro<100)
            {
                pro+=1;
                tiaoProgress.setProgress(pro);
                handler.sendMessageDelayed(Message.obtain(),100);
            }
            super.handleMessage(msg);
        }
    };
}


我们的XML文件:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context="com.example.xue.ui.MainActivity">


    <com.wls.tiaotiaotang.TiaoProgress
        android:id="@+id/sss"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

最后我们一定不要忘记加依赖:


allprojects {
    repositories {
        jcenter()
        maven { url 'https://jitpack.io'}//这是写进度条加的依赖
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'

    testCompile 'junit:junit:4.12'

    compile 'com.github.wlsj:TiaoTiao:V1.0'//这是写进度条加的依赖

}


以上就可以实现经过UI美化后的进度条.



  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值