gpt4 book ai didi

java - 如何创建自定义 ProgressBar

转载 作者:太空宇宙 更新时间:2023-11-03 13:40:38 25 4
gpt4 key购买 nike

编辑:
问题1)已解决。但我仍然无法更改为 colorProgressBar .我试着用我自己的 theme (见下面的代码)。

我想要我的 ProgressBar看起来像下图。我已经创建了一个 ProgressBar在我的 ListView 上方.我用的是ListView , ProgressBar , 和两个 TextViewsRelativeLayout .

我的问题:

1.) How can I align the TextViews above the ProgressBar in the way shown below?
2.) How can I set the Color of the ProgressBar itself and the Background Color of the ProgressBar?

enter image description here

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 the ProgressBar?

在你的 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>

会成功的。

输出:

enter image description here

关于java - 如何创建自定义 ProgressBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52672110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com