Moblie/Android
androidStudio/ProgressBar Style Custom
zyin
2022. 6. 19. 10:00
개요
- progressbar activity/fragment에 등록
- progressDrawable xml 만들기
- progressbar에 progressDrawable 등록
code
progressbar activity/fragment에 등록
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="32dp"
style="@android:style/Widget.ProgressBar.Horizontal"/>
</FrameLayout>
progressDrawable xml 만들기
- 아래에서는 progress를 background보다 아래에 두었다. 1과 2를 선언하는 순서에 따라 progress와 background중 어떤 것이 위에 와야 할지 정할 수 있다.
- scaleWidth는 전체를 얼마로 볼지를 의미한다. Progress의 android:max="100"의 항목과 유사하다.
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 1. progress 가 증가함에 따라 늘어나는 부분 -->
<item
android:id="@android:id/progress">
<scale
android:scaleWidth="100%">
<shape>
<corners android:radius="5dp"/>
<solid android:color="#F2B947"/>
</shape>
</scale>
</item>
<!-- 2. progress 의 배경 지정 -->
<item
android:id="@android:id/background">
<shape>
<corners android:radius="3dp"/>
<stroke
android:width="3dp"
android:color="#C6C1A3"/>
</shape>
</item>
</layer-list>
progressbar에 progressDrawable 등록
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="32dp"
android:progressDrawable="@drawable/custom_progressbar"
style="@android:style/Widget.ProgressBar.Horizontal"/>
</FrameLayout>