android - 细蓝色进度条

标签 android android-progressbar android-drawable

我正在尝试创建一个细长的蓝色进度条,类似于此:

enter image description here

我不太擅长使用 Drawables,但是我将 ProgressBar 更改为绿色,但我不确定如何使它变薄和变蓝:

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:orientation="vertical"
     >
      <ProgressBar 
        android:id="@+id/ProgressBar" 
        android:layout_centerInParent="true"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:progressDrawable="@drawable/progress"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:visibility="gone"
    />

</LinearLayout>

可绘制

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#ff9d9e9d"
                    android:centerColor="#ff5a5d5a"
                    android:centerY="0.75"
                    android:endColor="#ff747674"
                    android:angle="270"
            />
        </shape>
    </item>

    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#80ffd300"
                        android:centerColor="#80ffb600"
                        android:centerY="0.75"
                        android:endColor="#a0ffcb00"
                        android:angle="270"
                />
            </shape>
        </clip>
    </item>
    <item
        android:id="@android:id/progress"
    >
        <clip>
            <shape>
                <corners
                    android:radius="5dip" />
                <gradient
                    android:startColor="#33FF33"
                    android:endColor="#008000"
                    android:angle="270" />
            </shape>
        </clip>
    </item>

</layer-list>

最佳答案

高度由 android:layout_height="wrap_content 属性定义。例如,您可以将其设置为 2dp,以创建更细的进度条。

更改颜色会有点困难,因为您使用的是渐变。因此,您必须将开始和结束颜色更改为某种蓝色。

我在用什么

<ProgressBar
    android:id="@+id/progressbar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="4dp"
    android:layout_marginTop="0.01dp"
    android:max="100"
    android:progress="50"
    android:progressDrawable="@drawable/myprogressbar"
    android:secondaryProgress="0" />

MyProgressBar.xml在drawable文件夹中

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="0dip" />
            <gradient android:startColor="#C0C0C0" android:centerColor="#F8F8FF"
                android:centerY="0.75" android:endColor="#ffffff" android:angle="90" />
            <stroke android:width="0.01dp" android:color="#6B8E23" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="0dip" />
                <gradient android:startColor="#9ACD32" android:endColor="#FFFF00"
                    android:angle="90" />
                <stroke android:width="1dp" android:color="#6B8E23" />
            </shape>
        </clip>
    </item>
</layer-list>

用您自己的蓝色代码替换颜色代码:

android:startColor="#C0C0C0" android:centerColor="#F8F8FF" android:endColor="#ffffff"

关于android - 细蓝色进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15626796/

相关文章:

android - 更改进度条android的半透明背景颜色

android - 保持 ProgessDialog 直到执行回调

用于下载图像的 Android 加载指示器

安卓工作室 : Drawable Folder: How to put Images for Multiple dpi?

android - Android 模拟器的三星系统镜像?

android - Android 中的管道问题

Android 从一个对话框中显示另一个对话框

android - 使用 drawableLeft 将动画应用于 Drawable 集

android - 如果我需要按钮的小边框半径,为什么我们需要创建形状?

android - 单击按钮动态添加布局并从布局中获取文本?