2013-07-01 28 views
0

當前我正在爲我的錄音機做一些增強功能,現在我添加了振幅以獲取麥克風輸入電平並顯示給用戶以查看是否正在錄製音頻。它正在與dialog.setProgress();正常工作,但由於我非常想讓它在用戶面前很好地顯示,我打算改變它的顏色並隱藏進度背景,只顯示進度部分,這取決於進度級別。假設下面的20是綠色的40下面是黃色的60下面是橙色和紅色的60像我們在媒體播放器中看到的典型音頻水平。但我不知道爲什麼我甚至無法將我的進度條背景設置爲透明以及更改我的progressDrawable更改整個進度條。需要一些幫助。反正這裏的截圖和XML:Android進度條改變麥克風振幅的顏色

<ProgressBar 
       style="?android:attr/progressBarStyleHorizontal" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/mic_level" 
       android:indeterminate="false" 
       android:layout_below="@+id/chk_Record" 
       android:layout_alignParentLeft="true" 
       android:layout_marginTop="31dp" 
       android:layout_alignParentRight="true" 
       android:progress="50" 
       android:clickable="false" 
       android:progressDrawable="@color/holo_bright_blue" 
       android:background="@color/transparent"/> 

enter image description here

回答

0

您可以創建一個可繪製你的進度條,如下圖所示。這是我從我的一個項目中獲得的非常粗略的指導,所以你可能(幾乎肯定)不需要漸變,但至少應該給你一個粗略的想法。

以下使背景對於進度條透明,並將前景色更改爲綠色。

將這個在繪製文件夾,名字是在進度集progress_styles.xml現在:

android:progressDrawable="@drawable/progress_styles" 

<item android:id="@android:id/background"> 
    <shape> 
     <corners android:radius="5dip" /> 

     <gradient 
      android:startColor="@android:color/transparent" /> 
    </shape> 
</item> 
<item android:id="@android:id/secondaryProgress"> 
    <clip> 
     <shape> 
      <corners android:radius="5dip" /> 
      <gradient 
       android:startColor="#00ff00" /> 
     </shape> 
    </clip> 
</item> 
<item android:id="@android:id/progress"> 
    <clip> 
     <shape> 
      <corners android:radius="5dip" /> 
      <gradient 
       android:startColor="#00ff00" /> 
     </shape> 
    </clip> 
</item> 

我希望這可以幫助你。

+0

謝謝!明天會試用這個。實際上,我已經有了使用與此類似的東西的想法,但是我也很好奇並想知道爲什麼手動更改屬性會給我不同的結果,如我所料。這部分有點麻煩,因爲我不知道我的想法是否可行。 – KaHeL

+0

抱歉,我忘記標記爲正確答案。無論如何,這對我有幫助。我所做的是用我提到的配色方案爲此創建了4 xml。然後基於幅度水平以編程方式應用它。 :) 謝謝! – KaHeL

0

漸變角度可以幫助改變進度條狀態的變化顏色。

你必須創建爲自定義XML與layer,並添加item它像...

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:id="@android:id/background"> //---this is progress background 
</item> 
... 
<item android:id="@android:id/progress"> //----this is progress status 
</item> 
</layer-list> 

Check my this answer for detail, if it could help