を表示するアプリを開発中ですProgressBar
が、デフォルトの Android を置き換えたいと考えていますProgressBar
。
では、どのようにカスタマイズすればよいのでしょうかProgressBar
?
そのためにはグラフィックやアニメーションが必要ですか?
次の投稿を読みましたが、うまくいきませんでした。
ベストアンサー1
をカスタマイズするには、ProgressBar
プログレス バーの背景と進行状況の属性またはプロパティを定義する必要があります。
customprogressbar.xml
フォルダー内に次の名前の XML ファイルを作成しますres->drawable
。
カスタムプログレスバー.xml
<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>
次に、(drawable)progressDrawable
のプロパティを設定する必要があります。customprogressbar.xml
これは、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" />
実行時に次の操作を実行します
// Get the Drawable custom_progressbar
Drawable draw=res.getDrawable(R.drawable.custom_progressbar);
// set the drawable as progress drawable
progressBar.setProgressDrawable(draw);
編集: XMLレイアウトを修正しました