Android开关控件开关的使用案例

  

<强>在很多应用的设置页面,或者是一些功能的开关界面,我们常常用到开关(开关)来展示状态,今天说说开关控件。

  

<强>(1)布局文件代码

        & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:工具=" http://schemas.android.com/tools "   android: layout_width=" match_parent "   android: layout_height=" match_parent "   android: paddingBottom=" @dimen/activity_vertical_margin”   android: paddingLeft=" @dimen/activity_horizontal_margin”   android: paddingRight=" @dimen/activity_horizontal_margin”   android: paddingTop=" @dimen/activity_vertical_margin”   工具:上下文="。祝辞MainActivity”;   & lt;开关   android: id=癅 + id/switch2”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_alignParentLeft=" true "   android: layout_alignParentTop=" true "   android: layout_marginLeft=" 32 dp "   android: layout_marginTop=" 94 dp”   android:文本="开启震动”   android: textOff="关闭”   android: onClick=" onToggleClicked "   android: textOn="打开”/比;   & lt; TextView   android: id=癅 + id/textView1”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_alignLeft=癅 + id/switch2”   android: layout_alignParentTop=" true "   android: layout_marginTop=" 26 dp "   android:文本="开关的使用”   android: textSize=" 30 dp/比;   & lt;/RelativeLayout>      

<强>(2)控制的类

        包com.example.android_switch;   进口android.os.Bundle;   进口android.app.Activity;   进口android.view.Menu;   进口android.view.View;   进口android.widget.Switch;   进口android.widget.Toast;   进口android.widget.ToggleButton;   公开课MainActivity延伸活动{   @Override   保护无效alt=" Android开关控件开关的使用案例">

  

<强>总结

  

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接

Android开关控件开关的使用案例