SeekBar自定义

Java代码 复制代码

    <SeekBar android:id="@android:id/progress" 
            style="?android:attr/progressBarStyleHorizontal" 
            android:progressDrawable="@drawable/seekbar_style"    
            android:thumb="@drawable/thumb" 
            android:layout_width="fill_parent" 
            android:layout_height="23dip" 
            android:paddingLeft="25dip" 
            android:paddingRight="25dip" 
            android:paddingBottom="4dip /> 


其实最最关键的就是
Java代码 复制代码

    android:progressDrawable="@drawable/seekbar_style"    
    android:thumb="@drawable/thumb" 


怎么去定义呢?
看下面的代码:
seekbar_style.xml
Java代码 复制代码

    <?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="10dip" />    
             <gradient    
                 android:startColor="#ffffffff" 
                 android:centerColor="#ff000000"    
                 android:endColor="#ff808A87"   
                 android:centerY="0.45"    
                 android:angle="270"/>    
          </shape>    
       </item>    
         
       <item android:id="@android:id/progress">    
           <clip>    
              <shape>    
                  <corners android:radius="10dip" />    
                  <gradient    
                      android:startColor="#ffffffff" 
                      android:centerColor="#ffFFFF00"    
                      android:endColor="#ffAABD00"   
                      android:centerY="0.45"    
                      android:angle="270"/>    
              </shape>    
           </clip>    
       </item>    
     </layer-list>   



thumb.xml
Java代码 复制代码

    <?xml version="1.0" encoding="UTF-8"?>    
    <selector xmlns:android="http://schemas.android.com/apk/res/android">          
        <!-- 按下状态 -->   
        <item      
            android:state_pressed="true"      
            android:drawable="@drawable/xxxxxxxxxx" />     
                   
        <!-- 普通无焦点状态 -->   
        <item      
            android:state_focused="false"      
            android:state_pressed="false"    
            android:drawable="@drawable/xxxxxxx" />  
     
    上面的xxxxxxx是图片  
    </selector>   

你可能感兴趣的:(java,android,xml)