android 進度條seekbar樣式自訂

來源:互聯網
上載者:User

SeekBar是ProgressBar的擴充,在其基礎上增加了一個可拖動的thumb(註:就是那個可拖動的表徵圖)。使用者可以觸摸thumb並向左或向右拖動,再或者可以使用方向鍵都可以設定當前的進度等級。

布局檔案:

<SeekBar  android:id="@+id/seekbar"  android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:layout_alignParentBottom="true"  android:layout_marginBottom="10dp"  android:maxHeight="8dp"  android:minHeight="8dp"  android:progressDrawable="@drawable/seekbar_style"  android:thumb="@android:drawable/ic_notification_overlay"  android:thumbOffset="0dp" /><TextView  android:id="@+id/progress"  android:layout_width="fill_parent"  android:layout_height="wrap_content" />seekbar的樣式檔案:seekbar_style.xml<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  <item android:id="@android:id/background"><shape >          <corners android:radius="10dip" />          <gradient              android:angle="270"              android:centerColor="#F5F5F5"              android:centerY="0.45"              android:endColor="#F5F5F5"              android:startColor="#F5F5F5" />      </shape>  </item>  <item android:id="@android:id/progress"><clip >          <shape >              <corners android:radius="10dip" />              <gradient                  android:angle="270"                  android:centerColor="#FF75BC32"                  android:centerY="0.45"                  android:endColor="#FF75BC32"                  android:startColor="#FF75BC32" />          </shape>      </clip>  </item></layer-list>說明:如果想要改變進度條下面的那個白色的背景槽的顏色,在第一個item裡面進行設定,可以通過設定@null 或者#00000000來把進度槽隱藏掉,如果想要改變進度條的顏色,在第二個種修改成自己需要的顏色即可activity類:public class SeekbarActivity extends Activity implements  SeekBar.OnSeekBarChangeListener{private SeekBar mSeekBar;private TextView progressNum;  @Override  public void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      setContentView(R.layout.main);      mSeekBar=(SeekBar) findViewById(R.id.seekbar);      progressNum=(TextView) findViewById(R.id.progress);  }@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stubprogressNum.setText(String.valueOf(progress + 1));}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}}更複雜的邏輯,需要自己根據自己的業務區實現
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.