2

更改 的android:textOnandroid:textOff属性Switch在我的 S3 上不起作用。我的开关上的标签总是显示"ON""OFF"

Switch文档

<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"/>
4

2 回答 2

0

我刚刚在三星 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-01T15:53:12.947 回答
-1

试试下面的代码:

      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();
         }
         }
         });
于 2013-03-01T15:49:39.493 回答