프로그래스바 커스터마이징하기
조회수 10431회
현재 제작 중인 앱에 ProgressBar
를 사용하려 합니다. 안드로이드에서 기본적으로 제공하는 ProgressBar
가 아닌 커스터마이징한 ProgressBar
를 사용하고 싶은데 어떻게 해야하나요?
그래픽이나 애니메이션 작업이 필요하나요?
아래의 글을 참고했지만 실패했습니다.
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
1 답변
-
우측 링크의 블로그에 코드와 함께 예시가 설명되어 있습니다 : Customized Progress Bar In Android
ProgressBar
를 커스터마이징하려면 로딩바의 배경과 로딩 이미지에 대한 속성을 정의해야합니다.customprogressbar.xml
을res->drawable
디렉토리에 생성하세요.custom_progressbar.xmll
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 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="#007A00" android:centerColor="#007A00" android:centerY="1.0" android:endColor="#06101d" android:angle="270" /> </shape> </clip> </item> </layer-list>
이제
customprogressbar.xml
에progressDrawable
을 설정해야 합니다. 이는 XML 파일이나 액티비티에서 할 수 있습니다.아래 코드를 XML 파일에 삽입하세요 :
<ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleHorizontal" android:progressDrawable="@drawable/custom_progressbar" android:layout_width="wrap_content" android:layout_height="wrap_content" />
자바 코드에 아래 코드를 삽입하세요
// custom_progressbar을 불러옴 Drawable draw=res.getDrawable(R.drawable.custom_progressbar); // 로딩 이미지를 설정 progressBar.setProgressDrawable(draw);
댓글 입력