如何与一个切换按钮的Android合作 [英] how to work with a ToggleButton android
本文介绍了如何与一个切换按钮的Android合作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的切换按钮在XML:
I have the following ToggleButton in xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="46dp"
android:gravity="center" >
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="ToggleButton"
android:textOff="Inactive"
android:textOn="Active" />
<TextView
android:id="@+id/label_note"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginRight="38dp"
android:layout_marginLeft="2dip"
android:layout_toRightOf="@+id/check_note"
android:text="@+id/label"
android:textSize="25px" />
...
</RelativeLayout>
在我的类扩展列表视图,我想基于一些规定 - 以编程设定的切换按钮上的有效/无效。我想指定我没有什么用户能够点击切换按钮,放在有效或无效。怎么做?需要一些帮助。鸭preciate!
In my class that extends a listview I would like to programatically set the togglebutton on active/inactive based on some criterias. I would like to specify that I do not what the user to be able to click on the togglebutton and set it on active or inactive. How to do that? Need some help. Appreciate!
推荐答案
使按钮无法点击,只是禁用切换按钮:
to make the button not clickable, just disable the toggle button:
mToggleButton.setEbabled(false);
或将其设置不被点击:
mToggleButton.setClickable(false);
和编程的方法修改按钮状态,使用:
and for programatically change the button state, use:
mToggleButton.setActivated(true);
mToggleButton.setActivated(false);
这篇关于如何与一个切换按钮的Android合作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文