0
A
回答
1
要么你可以使用这样
<ProgressBar
android:id="@+id/simpleProgressBar"
style="@android:style/Widget.Holo.Light.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:max="100"
android:progress="0"
android:indeterminateOnly="true" />
默认进度条或很少有库也https://github.com/DreaminginCodeZH/MaterialProgressBar你可以尝试都和使用。
你可以用setProgress()方法设置progess。
样品的完整代码: - 按照这个
public class MainActivity extends AppCompatActivity {
int progress = 0;
ProgressBar simpleProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initiate progress bar and start button
simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
Button startButton = (Button) findViewById(R.id.startButton);
// perform click event on button
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// call a function
setProgressValue(progress);
}
});
}
private void setProgressValue(final int progress) {
// set the progress
simpleProgressBar.setProgress(progress);
// thread is used to change the progress value
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
setProgressValue(progress + 10);
}
});
thread.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
要更新进度的颜色
创建绘制一个XML文件 - > custom_progress.xml
<item>
<shape>
<gradient
android:endColor="#fff"
android:startColor="#1f1"
android:useLevel="true" />
</shape>
</item>
然后我们需要添加到我们的陆侃栏这个像下面,它会工作: -
<ProgressBar
android:id="@+id/simpleProgressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/custom_progress" />
相关问题
- 1. 设置进度,进度条
- 2. 如何设置进度条
- 3. 如何在android中设置进度条?
- 4. Flex进度条设置
- 5. 设置AJAX进度条
- 6. 如何使用getRepeaterItem设置进度条的进度?
- 7. Laravel 5.1 - 如何设置进度条
- 8. 如何设置为100%并重置为0%进度条
- 9. Swift:设置NSProgressIndicator的进度
- 10. 如何设置显示install4j中安装/更新进度的进度条?
- 11. 如何在JavaScript中为我的进度条设置百分比?
- 12. 如何在android中设置天文台的进度条?
- 13. 如何设置VerticalSeekBar的进度绘制?
- 14. Android:如何使这样的进度条
- 15. Python四步设置与进度条
- 16. 设置进度条为垂直
- 17. Visual Basic 2010 - 进度条 - 设置回0
- 18. 如何处置进度条?
- 19. 如何在jQuery中动态设置进度条值?
- 20. 如何在windows进度条中设置颜色渐变?
- 21. 如何在Android中设置自定义进度条
- 22. 如何在滑块中设置动画进度条
- 23. 如何在模拟器中设置进度条
- 24. 如何在RelativeLayout中设置ContentView? (进度条)
- 25. 如何在windows进度条控件中设置阈值?
- 26. 如何设置进度栏颜色?
- 27. 如何为进度DB设置ODBC 10.1b
- 28. 如何设置加密算法的进度条?
- 29. 如何以编程方式设置进度条的前景色?
- 30. 如何在spinner之前设置进度条?
把你的xml文件 – mac229
我还没有发现任何方式设置为XML那个吧,对于图标和文字他们很好 –
所以把你的java代码 – mac229