在Mono for Android中更改ProgressBar标准配色方案的简便方法?

时间:2013-09-10 11:14:12

标签: android progress-bar xamarin.android xamarin-studio

我正在寻找一种方法来改变Xamarin Studio中标准android ProgressBar的色调和背景颜色。找到一些关于如何在java中完成此操作的提示:

myprogress.setBackgroundDrawable(c.getResources().getDrawable(R.drawable.progress));

但我无法弄清楚如何在Xamarin中使用它。我也看过相当大的xml文件,制作渐变背景。但是,不应该有一种简单的方法来改变颜色而没有任何渐变?

2 个答案:

答案 0 :(得分:1)

你应该这样做。

res / values中的

通过添加

添加新样式
<style name="Theme.MyAppTheme.Process" parent="android:Theme.Light">
<item name ="android:background">#2D2D2D</item>
<item name ="background">#2D2D2D</item>
</style>

现在在ProgressBar中使用此样式。

myprogress.setProgressStyle(R.style.Process);

你可以在风格的背景中改变颜色代码..

答案 1 :(得分:0)

要将Java转换为C#,它将如下所示:

myprogress.SetBackgroundDrawable(Resources.GetDrawable(Resource.Drawable.progress));

您需要做的就是将您想要用作drawable(png,xml等)作为Resources / drawable文件夹中的背景。如果你只想要一个渐变,你应该使用xml而不是位图。在Resources / drawable文件夹中创建一个新的xml文件,这是一个蓝色渐变的示例:

<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient 
        android:startColor="#065b92"
        android:endColor="#1183ce"
        android:type="linear"
        />
</shape>