java-如何创建自定义ProgressBar
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-如何创建自定义ProgressBar,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2929字,纯文字阅读大概需要5分钟。
内容图文
![java-如何创建自定义ProgressBar](/upload/InfoBanner/zyjiaocheng/669/96d0515fc0f4460db563696744c2dca3.jpg)
编辑:
问题1)已解决.但是我仍然无法更改ProgressBar的颜色.我尝试使用自己的主题(请参见下面的代码).
我希望我的ProgressBar看起来像下面的图像.我已经在ListView上方创建了一个ProgressBar.我在RelativeLayout中使用ListView,ProgressBar和两个TextView.
我的问题:
1.) How can I align the
TextViews
above theProgressBar
in the way shown below?
2.) How can I set the Color of theProgressBar
itself and the Background Color of theProgressBar
?
MainActivity.xml
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/progressBarText"
android:progress="0"
android:max="100"
android:paddingTop="0dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:theme="@style/progressBarTheme"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@android:color/holo_green_dark</item>
</style>
<style name="progressBarTheme" parent="@style/Theme.AppCompat">
<item name="colorAccent">@color/myRedColor</item>
</style>
</resources>
解决方法:
1.) How can I align the TextViews above the ProgressBar in the way shown below?
尝试这个:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<ProgressBar
android:id="@+id/progressCircle"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<TextView
android:id="@+id/txtvStatusCircle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/progressCircle"
android:layout_alignParentStart="true"
android:text="Daily Progress"
android:textSize="18sp" />
<TextView
android:id="@+id/txtPercent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/progressCircle"
android:layout_alignParentEnd="true"
android:text="0 %"
android:textSize="18sp" />
</RelativeLayout>
2.) How can I set the Color of the
ProgressBar
itself and the Background Color of theProgressBar
?
在您的styles.xml中:
<style name="progressBarBlue" parent="@style/Theme.AppCompat">
<item name="colorAccent">@color/myBlueColor</item>
</style>
然后在xml中设置为ProgressBar主题:
<ProgressBar
...
android:theme="@style/progressBarBlue" />
关于ProgressBar本身,无论您为样式中的AccentColor选择什么,都将为ProgressBar设置.因此更改颜色:
<item name="colorAccent">@color/colorAccent/item>
会成功的.
输出:
内容总结
以上是互联网集市为您收集整理的java-如何创建自定义ProgressBar全部内容,希望文章能够帮你解决java-如何创建自定义ProgressBar所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。