2014-09-18 7 views
0

파일을 다운로드하는 동안 진행률 막대가 표시됩니다. 서버에서 제공되는 진행률의 색상 (HTML 색상 코드)을 설정하고 때로는 색상 코드가 다를 수 있습니다. 요구 사항을 어떻게 충족합니까?프로그래밍 방식으로 진행률 막대 진행 색상을 설정하십시오.

image.

예를 들어 위의 이미지에서 나는 노란 색을 바꾸고 서버에 오는 색을 설정하고 싶습니다.

+0

http://stackoverflow.com/questions/2020882이 유용을 찾을 수 있습니다 더 많은 정보를 위해 건배

/how-to-change-progress-bars-progress-color-in-android –

+0

확인 : http://stackoverflow.com/questions/5745814/android-change-horizonal-progress-bar-color –

+0

@HareshChhelana 코드를 통해 색상을 설정하고 싶습니다. – Meher

답변

1

그래서 ... 진행률 색상을 변경하는 샘플 프로젝트를 만들었고 백그라운드 진행률 막대 색상을 변경할 수도 있습니다.

먼저 사용자 정의 진행률 표시 줄 XML 파일을 만듭니다.

custom_progressbar.xml

<!-- Define the background properties like color etc --> 
<item android:id="@android:id/background"> 
    <shape> 
     <gradient 
      android:startColor="#000001" 
      android:centerColor="#0b131e" 
      android:centerY="1.0" 
      android:endColor="#0d1522" 
      android:angle="270" 
      /> 
    </shape> 
</item> 

<!-- Define the progress properties like start color, end color etc --> 
<item android:id="@android:id/progress"> 
    <clip> 
     <shape> 
      <gradient 
       android:startColor="#2A98E1" 
       android:centerColor="#2A98E1" 
       android:centerY="1.0" 
       android:endColor="#06101d" 
       android:angle="270" 
       /> 
     </shape> 
    </clip> 
</item> 

활동 레이아웃 :

activity_my.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:orientation="horizontal" 
tools:context=".MyActivity"> 


<ProgressBar 
    android:id="@+id/myProgress" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="match_parent" 
    android:layout_weight="0.7" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:id="@+id/progressTextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 

    android:text="None"/> 

</LinearLayout> 

테스트 활동

중요한 부분이됩니다.

그리기 연신의 GetResources =() getDrawable (R.drawable.custom_progressbar); progressBar.setProgressDrawable (draw);

MyActivity.java

private ProgressBar progressBar; 
private Handler handler = new Handler(); 
private int progressStatus = 0; 
private TextView textView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_my); 



    init(); 
    initProgresBar(); 

} 


public void init(){ 

    textView = (TextView) findViewById(R.id.progressTextView); 
    progressBar = (ProgressBar) findViewById(R.id.myProgress); 
    Drawable draw=getResources().getDrawable(R.drawable.custom_progressbar); 
    // set the drawable as progress drawable 
    progressBar.setProgressDrawable(draw); 

} 

public void initProgresBar(){ 
    new Thread(new Runnable() { 
     public void run() { 
      while (progressStatus < 100) { 
       progressStatus += 1; 
       // Update the progress bar and display the 

       //current value in the text view 
       handler.post(new Runnable() { 
        public void run() { 
         progressBar.setProgress(progressStatus); 
         textView.setText(progressStatus+"/"+progressBar.getMax()); 
        } 
       }); 
       try { 
        // Sleep for 200 milliseconds. 

        //Just to display the progress slowly 
        Thread.sleep(200); 
       } catch (InterruptedException e) { 
        e.printStackTrace(); 
       } 
      } 
     } 
    }).start(); 

} 

그리고 출력이 될 것이다 :

enter image description here

희망이 당신이 어디에서 찾고있는 것입니다. stack progress bar post

+0

처음에는 COLOR.RED.the 전체 진행 막대를 빨간색으로 시도하고 진행 상황을 볼 수 없습니다. – Meher

+0

OK 샘플 ​​예제를 다시 보겠습니다 :) –

+0

감사합니다.하지만이 진행률 표시 줄은 xml.how에 설정되어 있습니다. 자바 코드를 사용하여 색상을 변경합니까? – Meher

0
progressBar.getProgressDrawable().setColorFilter(Color.parseColor("#YourColorHex"), Mode.SRC_IN); 

Tutorial for Customizing ProgressBar

편집 :

http://miroprocessordev.blogspot.in/2012/09/android-how-to-change-progress-bar.html

+0

색상을 설정하면 색상이 완전히 채워집니다. 진도를 볼 수 없습니다. 다른 점은 무엇입니까? – Meher

+0

당신은'progressBar.setProgress (0);'를 사용하고 있습니까? –

+0

다운로드 시작 전에 예. – Meher

관련 문제