更改android:textOn和android:textOff属性Switch不适用于我的S3。我的开关上的标签总是显示“开”和“关”。
Documentation
<Switch
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="@string/on"
android:textOff="@string/off"
android:includeFontPadding="false"/>发布于 2013-03-01 15:53:12
我刚刚在三星的Galaxy S3上测试了这个,它运行得很好。
这是我的XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/switch1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:textOn="CHANGEMEON"
android:textOff="CHANGEMOFF"
android:text="ToggleButton" />
</RelativeLayout>发布于 2013-03-01 15:49:39
尝试以下代码:
toggle=(ToggleButton)findViewById(R.id.tglbtn);
toggle.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(toggle.isChecked())
{
Toast.makeText(getApplicationContext(), "The state is changed to on", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "The state is changed to off", Toast.LENGTH_LONG).show();
}
}
});https://stackoverflow.com/questions/15161417
复制相似问题