ProgressBar 像电池充电

ProgressBar like Battery Charging

我需要一个想法来开发像 Battery Indicator 符号一样的 ProgressBar。这意味着需要覆盖 Spinner Icon。

虽然我的进程正在进行,但我需要显示 ProgressBar 之类的电池更换并增加进度百分比,直到完成。 (100%).

电池指示器可以在 http://www.flaticon.com/search?word=battery 上找到并计算为一个简单的进度条。

使用条件语句显示与已完成工作百分比相关的电池状态图标。

 public class MyActivity extends Activity {
 private static final int PROGRESS = 0x1;

 private ProgressBar mProgress;
 private int mProgressStatus = 0;

 private Handler mHandler = new Handler();

 protected void onCreate(Bundle icicle) {
     super.onCreate(icicle);

     setContentView(R.layout.progressbar_activity);

     mProgress = (ProgressBar) findViewById(R.id.progress_bar);

     // Start lengthy operation in a background thread
     new Thread(new Runnable() {
         public void run() {
             while (mProgressStatus < 100) {
                 mProgressStatus = doWork();

                 // Update the progress bar
                 mHandler.post(new Runnable() {
                     public void run() {
                         mProgress.setProgress(mProgressStatus);
                     }
                 });
             }
         }
     }).start();
 }
 }

doWork 方法中执行繁重的 cpu 工作并设置适当的图标。

我从 here 获得了 11 级电池电量 ICONS。我根据进度更新图像。

所以它就像进度更新一样来了。

感谢DEVIAN-ART