首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android: android:textOn和android:textOff开关不工作

Android: android:textOn和android:textOff开关不工作
EN

Stack Overflow用户
提问于 2013-03-01 15:39:30
回答 2查看 899关注 0票数 2

更改android:textOnandroid:textOff属性Switch不适用于我的S3。我的开关上的标签总是显示“开”和“关”。

Documentation

代码语言:javascript
复制
<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"/>
EN

回答 2

Stack Overflow用户

发布于 2013-03-01 15:53:12

我刚刚在三星的Galaxy S3上测试了这个,它运行得很好。

这是我的XML

代码语言:javascript
复制
<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>
票数 0
EN

Stack Overflow用户

发布于 2013-03-01 15:49:39

尝试以下代码:

代码语言:javascript
复制
      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();
         }
         }
         });
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15161417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档