自定义switchCompat背景样式+动画

自定义switchCompat样式

翻了一遍switchCompat详解,要想自己改掉原生样式成上图样板,改掉原生track 和 thumb即可, 话不多说上demo

新建thumb_selector:



thumb_on 和 thumb_off 样式:

   

       

       

       

   

       

       


       

           

           

        android:gravity="center" >

       

           

           


track_selector , track_on, track_off :



   

   


   

   

   


   

   

   

   


xml 中引用如下:

    android:id="@+id/switch_compat"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    app:switchMinWidth="56dp"

    android:background="@null"

    app:track="@drawable/track_selector"

    android:thumb="@drawable/thumb_selector"

    app:theme="@style/switchStyle"/>


有些机型可能还是会展示原生样式, 则需自己把原生样式统统去掉,styles.xml新增:

xml中用app:theme调用即可。

OK啦~~~~~·

你可能感兴趣的:(自定义switchCompat背景样式+动画)