Android toggle button custom look

后端 未结 4 1351
刺人心
刺人心 2020-11-27 05:44

I\'ve been trying to customize the toggle button look but with no success. Here is how I want it to look like:

\

4条回答
  •  爱一瞬间的悲伤
    2020-11-27 06:03

    I don't know if this is the best solution but it worked fine for me:

    1.- Decide how big do you want the toggle button. In my case width 56dp and height 76dp.

    2.- Create the icon set 56px-76px for mdpi, 84px-113px hdpi, same for xhdpi and xxhdpi

    3.- Move the icons in the corresponding drawable folder. In my case 20 icons 5 in each folder, named ic_name1_on, ic_name1_off [...] ic_name5_off

    4.- Create the following xml files in a new folder called drawable (if it does not exist yet):

    • ic_name1_toggle.xml
    • ic_name1_toggle_bg.xml
    • ic_name2_toggle.xml
    • (...)
    • ic_name5_toggle_bg.xml

    5.- In ic_name1_toggle.xml the code must be:

    
        
        
    
    

    6.- In ic_name1_toggle_bg.xml the code must be:

    
    
       
       
    
    

    7.- Finally in your layout.xml:

    
    

提交回复
热议问题