1
我試圖設置SwitchCompat
上的文本,但它不起作用。它只是第一次工作。但是,當你試圖改變文本(例如,當按鈕被點擊),它不起作用。SwitchCompat setTextOn()和setTextOff()在運行時不起作用
例如:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final SwitchCompat switchCompat = (SwitchCompat)findViewById(R.id.switch_test);
switchCompat.setTextOn("Yes");
switchCompat.setTextOff("No");
switchCompat.setShowText(true);
Button buttonTest = (Button)findViewById(R.id.button_test);
buttonTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switchCompat.setTextOn("YOO");
switchCompat.setTextOff("NAH");
//switchCompat.requestLayout(); //tried to this but has no effect
//switchCompat.invalidate(); //tried to this but has no effect
}
});
}
你會看到這些內容一直爲是和沒有。我試圖撥打requestLayout()
和invalidate()
沒有成功。任何想法?
很好的解決方案!我發佈了相同的答案,但你先來:) –
誰是我的男人?誰是我的男人!?!? Azizbekian是我的男人!感謝隊友,它的工作! – Sam