ToggleButton Text Label Placement for On and Off State

前端 未结 5 1957
暗喜
暗喜 2021-01-03 00:38

Is there anyway to control the text position for a ToggleButton\'s on and off state? For instance, I want the text label to be left aligned when on and right aligned when of

5条回答
  •  一个人的身影
    2021-01-03 01:33

    ToggleButton b1 = (ToggleButton) findViewById(R.id.button1);
            if(b1.isChecked()){
                b1.setGravity(Gravity.RIGHT);
            }
            else{
                b1.setGravity(Gravity.LEFT);
            }
    

    Note, that you will not see any changes if the button is not of a minimum size (has to be bigger than the lable text).

提交回复
热议问题