Switch-Button thumb gets skewed?

后端 未结 4 1239
说谎
说谎 2020-12-31 12:28

The thumb for my Switch-button seems to get skewed(for on&off state). There were similar problems on github, but those were for people making libraries to support Switch

4条回答
  •  醉话见心
    2020-12-31 12:59

    No clue why this happens but solved it by placing the Switch-button within a linearLayout. There must be some propery(width) of the thumb that has a "match_parent" of some sort that must've been causing it.

    Edit: It happens when I remove the default 'ON' and 'OFF' text. So to hide the text i changed its color to white. How to change textcolor of switch in Android

    main.java

    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.toggle_button);
    
        Switch sw = (Switch) findViewById(R.id.switch1);
    
                //Both of these need to be used to change the text color to white
                sw.setTextColor(Color.WHITE);
        sw.setSwitchTextAppearance(this, Color.WHITE);
    
                //Doing this would skew the circle
                //sw.setTextOn("  ");
        //sw.setTextOff("   ");
    }
    

    main.xml

    
    
    
    
        
    
    

提交回复
热议问题