Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在ProgressDialog中更改progressBar颜色_Android_Progressdialog_Android Progressbar - Fatal编程技术网

Android 在ProgressDialog中更改progressBar颜色

Android 在ProgressDialog中更改progressBar颜色,android,progressdialog,android-progressbar,Android,Progressdialog,Android Progressbar,我只想在ProgressDialog(水平样式)中更改progressBar的颜色。所以我创建了这个自定义形状xml文件 <?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>

我只想在ProgressDialog(水平样式)中更改progressBar的颜色。所以我创建了这个自定义形状xml文件

<?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="3dip" />
        <gradient
                android:startColor="#ff9d9e9d"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:angle="270"
        />
    </shape>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
             <corners android:radius="3dip" />
             <size android:height="3dip"/>              
            <gradient
                android:startColor="#33FF33"
                android:endColor="#008000"
                android:angle="270" />
        </shape>
    </clip>
</item>
</layer-list>

下面是结果(在Android 4.4下)

它看起来像安卓2.x。我希望它像Android 4.x一样薄,如下所示:

我还试图设置
,但没有成功


有什么想法吗?提前谢谢

尝试在您指定progressbar的布局xml文件中设置高度

<ProgressBar
    android:id="@+id/progBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="8dp"   <!-- THIS WILL SET HEIGHT OF PROGRESS BAR -->
    android:layout_centerHorizontal="true"
    android:layout_margin="10dp"
    android:max="100"
    android:progressDrawable="@drawable/customprogressbar" />

您可以使用LayoutParams

        ProgressBar progressBar = new ProgressBar(MainActivity.this, null,          android.R.attr.progressBarStyleHorizontal);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(300, 10);

        progressBar.setLayoutParams(params);
        LinearLayout test = new LinearLayout(getApplicationContext());
        test.addView(progressBar);
        setContentView(test);
您可以使用项目的标记, 顶部、底部以更改项目的高度

<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background"
          android:top="5dp"
          android:bottom="5dp">
        <color android:color="@color/red"/>
    </item>
    <item android:id="@android:id/progress"
          android:top="5dp"
          android:bottom="5dp">
        <clip>
            <color android:color="@color/blue"/>
        </clip>
    </item>
</layer-list>


我在代码中创建了它,但我不知道如何以编程方式设置这些属性。当我调用progress.show()时;如上图所示,在您的布局xml文件中,progressbar的高度设置为android:layout_height=“8dp”,但正如我所说,我是以编程方式创建progressDialog的,我没有在任何xml资源中定义:(哦,明白了!对不起!!在您的情况下,您可以在形状标记中的可绘制文件中添加这条线。请参阅。您是否能够解决它?
<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background"
          android:top="5dp"
          android:bottom="5dp">
        <color android:color="@color/red"/>
    </item>
    <item android:id="@android:id/progress"
          android:top="5dp"
          android:bottom="5dp">
        <clip>
            <color android:color="@color/blue"/>
        </clip>
    </item>
</layer-list>