Android 프로 그래 밍 사용자 정의 진도 바 색상 방법 상세 설명

이 사례 는 안 드 로 이 드 프로 그래 밍 이 진도 항목 의 색 을 정의 하 는 방법 을 설명 한다.여러분 께 참고 하도록 공유 하 겠 습 니 다.구체 적 으로 는 다음 과 같 습 니 다.
효과 그림 먼저 보기:

항상 각종 수요 문 제 를 제기 합 니 다.저 는 시스템 의 기본 색상 이 매우 좋다 고 생각 합 니 다.그러나 Pk 는 누가 우 리 를 수요 인원 이 아니 라 고 부 릅 니까?고 쳐 주세요!
이 건 어 쩔 수 없어 요.원본 만 볼 수 있어 요.다행히 원본 을 다운 받 았 습 니 다.sources\base\core\res\res\\\아래 에 없 는 게 없어 요.진도 바 색상 을 수정 하면 progress 만 찾 을 수 있어 요.스타일 을 바 꾸 는 거 니까 먼저 styles.xml 을 찾 아 보 세 요.
xml 를 찾 은 후 들 어가 서 찾 습 니 다:

<style name="Widget.ProgressBar">
 <item name="android:indeterminateOnly">true</item>
 <itemname="android:indeterminateDrawable">@android:drawable/progress_medium_white</item>
 <item name="android:indeterminateBehavior">repeat</item>
 <item name="android:indeterminateDuration">3500</item>
 <item name="android:minWidth">48dip</item>
 <item name="android:maxWidth">48dip</item>
 <item name="android:minHeight">48dip</item>
 <item name="android:maxHeight">48dip</item>
</style>

이것 은 그 기본 회전 입 니 다.그러나 오늘 우 리 는 이것 을 수정 하지 않 습 니 다.우 리 는 수평 진도 항목 의 색 을 바 꾸 려 고 하기 때문에 찾 았 습 니 다.

<style name="Widget.ProgressBar.Horizontal">
 <item name="android:indeterminateOnly">false</item>
 <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
 <itemname="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
 <item name="android:minHeight">20dip</item>
 <item name="android:maxHeight">20dip</item>
</style>

시스템 이 한 걸음 한 걸음 연결 되 어 있 는 것 을 보 세 요.확장 성 이 매우 높 고 낮은 결합 입 니 다.그래서 우 리 는 지금 진도 바 가 어떻게 그 려 졌 는 지 바 꾸 기만 하면 됩 니 다.그러나 진도 바 를 그 리 는 것 은입 니 다.  그래서'drawable 아래 progress'를 찾 을 수 있 습 니 다.horizontal 파일,그 를 바 꾸 면 진행 색상 을 바 꿀 수 있 습 니 다.

<?xml version="1.0" encoding="utf-8"?>
<!--
 Copyright (C) 2008 The Android Open Source Project
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
 <item android:id="@android:id/background">
 <shape>
  <corners android:radius="5dip" />
  <gradient
  android:angle="270"
  android:centerColor="#ff5a5d5a"
  android:centerY="0.75"
  android:endColor="#ff747674"
  android:startColor="#ff9d9e9d" />
 </shape>
 </item>
 <item android:id="@android:id/secondaryProgress">
 <clip>
  <shape>
  <corners android:radius="5dip" />
  <gradient
   android:angle="270"
   android:centerColor="#80ffb600"
   android:centerY="0.75"
   android:endColor="#a0ffcb00"
   android:startColor="#80ffd300" />
  </shape>
 </clip>
 </item>
 <item android:id="@android:id/progress">
 <clip>
  <shape>
  <corners android:radius="5dip" />
  <gradient
   android:angle="270"
   android:centerColor="#ffffb600"
   android:centerY="0.75"
   android:endColor="#ffffcb00"
   android:startColor="#ffffd300" />
  </shape>
 </clip>
 </item>
</layer-list>

보 셨 습 니까?이것 은 시스템 의 진도 가 그 려 진 구조 조건 입 니 다.

android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:endColor="#ff747674"

우 리 는 이 색 값 만 바 꾸 면 그의 색 을 바 꿀 수 있 습 니 다.주로아래 의 색 값 을 바 꾸 면 됩 니 다.
이렇게 많은 말 을 했 는데 도대체 어떻게 하 는 거 야?아주 간단 해.
프로젝트 다음 에 style.xml 파일 을 새로 만 듭 니 다.
style 탭 을 만 들 고 시스템 기본 스타일 을 통합 한 다음 새로운 progressDrawable 파일 을 사용자 정의 합 니 다.레이아웃 에 있 는 progress 에서 이 파일 을 참조 하면 됩 니 다.

<style name="ProgressBar_Mini" parent="@android:style/Widget.ProgressBar.Horizontal">
 <item name="android:maxHeight">50dip</item>
 <item name="android:minHeight">8dip</item>
 <item name="android:indeterminateOnly">false</item>
 <itemname="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
 <item name="android:progressDrawable">@drawable/progressbar_mini</item>
</style>

다음은 나의 progressbar미니 파일,색상 값 변경android:endColor="#F5F5F5"android:startColor="#BEBEBE"

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
 <item android:id="@android:id/background">
 <shape>
  <corners android:radius="5dip" />
  <gradient
  android:angle="270"
  android:centerY="0.75"
  android:endColor="#F5F5F5"
  android:startColor="#BEBEBE" />
 </shape>
 </item>
 <item android:id="@android:id/secondaryProgress">
 <clip>
  <shape>
  <corners android:radius="0dip" />
  <gradient
   android:angle="270"
   android:centerY="0.75"
   android:endColor="#165CBC"
   android:startColor="#85B0E9" />
  </shape>
 </clip>
 </item>
 <item android:id="@android:id/progress">
 <clip>
  <shape>
  <corners android:radius="5dip" />
  <gradient
   android:angle="270"
   android:centerY="0.75"
   android:endColor="#165CBC"
   android:startColor="#85B0E9" />
  </shape>
 </clip>
 </item>
</layer-list>

마지막 으로 인용 하면 됩 니 다.

<ProgressBar
 android:id="@+id/progress"
 style="@style/ProgressBar_Mini"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:progress="50" />

더 많은 안 드 로 이 드 관련 내용 에 관심 이 있 는 독자 들 은 본 사이트 의 주 제 를 볼 수 있다.,,,,Android 개발 입문 및 진급 강좌,Android 디 버 깅 기법 과 일반적인 문제 해결 방법 을 모 았 습 니 다.,안 드 로 이 드 멀티미디어 조작 기법 모음(오디 오,비디오,녹음 등),Android 기본 구성 요소 사용법 요약Android 보기 기술 요약
본 고 에서 말 한 것 이 여러분 의 안 드 로 이 드 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.

좋은 웹페이지 즐겨찾기