Android下修改SeekBar樣式的解決辦法

來源:互聯網
上載者:User

SeekBar設定檔:
Xml代碼 複製代碼 代碼如下:<SeekBar
android:id="@+id/player_seekbar"
android:layout_width="245px"
android:layout_height="25px"
android:progressDrawable="@drawable/seekbar_style"
android:thumb="@drawable/thumb"
android:paddingLeft="16px"
android:paddingRight="15px"
android:paddingTop="5px"
android:paddingBottom="5px"
android:progress="0"
android:max="0"
android:secondaryProgress="0"
/>

android:progressDrawable="@drawable/seekbar_style"背景條
seekbar_style配置如下:
Xml代碼複製代碼 代碼如下:<?xml version="1.0" encoding="UTF-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270"
/>
</shape>
</item>

<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="270"
/>
</shape>
</clip>
</item>

<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ff0099CC"
android:centerColor="#ff3399CC"
android:centerY="0.75"
android:endColor="#ff6699CC"
android:angle="270"
/>
</shape>
</clip>
</item>

</layer-list>

或者:用圖片如下:
Xml代碼複製代碼 代碼如下:<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background"
android:drawable="@drawable/progress_bg" />

<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/second_progress">
</item>

<item android:id="@android:id/progress"
android:drawable="@drawable/first_progress">

</item>
</layer-list>

方形
Xml代碼複製代碼 代碼如下:<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/progress_bg" />
<item android:id="@android:id/secondaryProgress">
<clip android:drawable="@drawable/second_progress" />
</item>
<item android:id="@android:id/progress">
<clip android:drawable="@drawable/first_progress" />
</item>
</layer-list>

android:thumb="@drawable/thumb"就是那個會動的球
配置如下:
Xml代碼複製代碼 代碼如下:<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- 按下狀態-->
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/thumb_pressed" />
<!-- 普通無焦點狀態 -->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/thumb_normal" />
<!-- 有焦點狀態-->
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/thumb_focused" />
<!-- 有焦點 -->
<item
android:state_focused="true"
android:drawable="@drawable/thumb_focused" />
</selector>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.