状态开关(ToggleButton)
生活随笔
收集整理的這篇文章主要介紹了
状态开关(ToggleButton)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
狀態開關(ToggleButton):
常用屬性:isChecked(是否被選中,如true)
監聽:1.監聽方法:setOnCheckedChangeListener
2.監聽器:CompoundButton.OnCheckedChangeListener
1.Activity
//狀態的開關 public class ToggleButtonActivity extends Activity {private ToggleButton toggleButton;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.toggle_button);toggleButton = (ToggleButton)findViewById(R.id.toggleButtonId);toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if(isChecked){Toast.makeText(ToggleButtonActivity.this, "無線網絡打開了!", Toast.LENGTH_SHORT).show();}else{Toast.makeText(ToggleButtonActivity.this, "無線網絡關閉了!", Toast.LENGTH_SHORT).show();}}});} }2.xml文件
<?xml version="1.0" encoding="utf-8"?> <!-- 狀態的開關頁面 --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"android:padding="5dp" ><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="無線網:"android:textSize="20sp" /><ToggleButtonandroid:id="@+id/toggleButtonId"android:layout_width="wrap_content"android:layout_height="wrap_content" /></LinearLayout>3.效果顯示圖
轉載于:https://www.cnblogs.com/wuziyue/p/5470376.html
總結
以上是生活随笔為你收集整理的状态开关(ToggleButton)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 30万级电动轿跑哪吒S全车无实体按键!官
- 下一篇: 谷歌学术网站镜像