Android: Create a toggle button with image and no text

前端 未结 4 717

is it possible to create a toggle button in Android that has an image but no text? Ideally it would look like this:

4条回答
  •  难免孤独
    2020-11-30 18:51

    1. Can I replace the toggle text with an image

      No, we can not, although we can hide the text by overiding the default style of the toggle button, but still that won't give us a toggle button you want as we can't replace the text with an image.

    2. How can I make a normal toggle button

      Create a file ic_toggle in your res/drawable folder

      
      
          
      
          
      
      
      

      Here @drawable/ic_slide_switch_on & @drawable/ic_slide_switch_off are images you create.

      Then create another file in the same folder, name it ic_toggle_bg

      
      
      
          
      
          
      
      
      

      Now add to your custom theme, (if you do not have one create a styles.xml file in your res/values/folder)

      
      
      
      

      This creates a custom toggle button for you.

    3. How to use it

      Use the custom style and background in your view.

        
      

提交回复
热议问题