的RelativeLayout和切换按钮
问题描述:
这是我的main.xml的RelativeLayout和切换按钮
<RelativeLayout android:id="@+id/gloabal_permission"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:background="@drawable/settings_selector_down"
android:paddingTop="3dp" android:paddingBottom="3dp"
android:paddingRight="12dp" android:paddingLeft="15dp">
<TextView android:id="@+id/TextView06"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="Gloabal permission" android:layout_marginTop="10dp">
</TextView>
<ToggleButton android:id="@+id/globalpermissionbutton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="ToggleButton" android:layout_alignParentRight="true">
</ToggleButton>
</RelativeLayout>
我应该怎么做,当我点击切换按钮的RelativeLayout是打开(点击一次切换按钮已关闭)。我只是用togglebutton的监听器绑定relativelayoutlistener。
答
你必须为你的相对布局创建一个onClick()侦听器。例如,
yourRelLayout.setOnClickListener(new OnClickListener({
yourToggleButton.setChecked(true);
}));
,这是所有:)
祝你好运!
您是说当您点击它时,此切换按钮未设置为打开或关闭状态? – Cata
我只想看任何例子如何做到这一点。 – fish40
但你的例子不起作用? – Cata