Android:Android:textOn和Android:textOff开启开关不工作
更改Switch的android:textOn和android:textOff属性在我的S3上不起作用。我的开关上的标签总是显示on和OFFAndroid:Android:textOn和Android:textOff开启开关不工作,android,Android,更改Switch的android:textOn和android:textOff属性在我的S3上不起作用。我的开关上的标签总是显示on和OFF 请尝试以下代码: toggle=(ToggleButton)findViewById(R.id.tglbtn); toggle.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-gene
请尝试以下代码:
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();
}
}
});
请尝试以下代码:
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();
}
}
});
我刚刚在三星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>
我刚刚在三星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>
它在等效的仿真器中工作吗?如果是的话,那么三星可能弄乱了ToggleButton的实现。Switch小部件有稳定的后端口吗?它在同等的仿真器中工作吗?如果是,那么三星可能弄乱了ToggleButton的实现。Switch小部件是否有稳定的后端口?我不知道这个答案与这个问题有什么关系。我正在各种型号上测试我的应用程序,我意识到toggle button on and OFF事件不起作用。这是设备列表:三星YS5360三星Galaxy Note三星S Plus HTC轰动XE HTC Wildfire S摩托罗拉RAZR LG Optimus Black索尼爱立信Xperia neo V,但我已经实现了上面的代码,它正在工作检查一次……我不知道这个答案与这个问题有什么关系。我正在各种型号上测试我的应用程序,我有意识到切换按钮ON和OFF事件不起作用。这是设备列表:三星YS5360三星Galaxy Note三星S Plus HTC轰动XE HTC Wildfire S摩托罗拉RAZR LG Optimus Black索尼爱立信Xperia neo V,但我已经实现了上面的代码它正在工作检查一次……这是使用一个切换按钮而不是开关,虽然文本标签正确,但它是另一个UI元素/如果需要开关,则不理想。这是使用切换按钮而不是开关,虽然文本标签正确,但它是另一个UI元素/如果需要开关,则不理想。