Android控制之ToggleButton和Switch与RatingBar
来源:互联网 发布:东华软件金融部 编辑:程序博客网 时间:2024/05/22 14:50
代码演示
Android控制之ToggleButton和Switch与RatingBar
.java文件:
package com.example.togglebuttonandratingbar;import android.app.Activity;import android.os.Bundle;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.RatingBar;import android.widget.RatingBar.OnRatingBarChangeListener;import android.widget.Switch;import android.widget.Toast;import android.widget.ToggleButton;public class MainActivity extends Activity implements OnCheckedChangeListener,OnRatingBarChangeListener { private ToggleButton toggleButton; private Switch sw; private RatingBar rb; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initUI(); } private void initUI() { toggleButton=(ToggleButton) findViewById(R.id.ToggleButton1); toggleButton.setOnCheckedChangeListener(this); sw=(Switch)findViewById(R.id.Switch1); sw.setOnCheckedChangeListener(this); rb=(RatingBar) findViewById(R.id.ratingBar2); rb.setOnRatingBarChangeListener(this); } @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub switch (buttonView.getId()) { case R.id.Switch1: Toast.makeText(getApplicationContext(), sw.getText()+"/"+isChecked, 1000).show(); break; case R.id.ToggleButton1: Toast.makeText(getApplicationContext(), toggleButton.getText()+"/"+isChecked, 1000).show(); } } @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { // TODO Auto-generated method stub //如果来自用户选择:我们就Tuast一下星星的数量 if(fromUser) { Toast.makeText(getApplicationContext(),"当前选择的星星数量是:"+rating, 1000).show(); } }}
XML布局文件:
<LinearLayout 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="com.example.togglebuttonandratingbar.MainActivity" android:orientation="vertical"> <ToggleButton android:id="@+id/ToggleButton1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textOff="关闭" android:textOn="开启" /> <Switch android:id="@+id/Switch1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我是一个Switch" android:textOn="开启" android:textOff="关闭" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我是一个指示器你不能选择我:" /> <RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numStars="6" android:stepSize="1" android:rating="1" android:isIndicator="true" android:layout_gravity="center"/> <!--设置为 wrap_contentnumStars,numStars才起作用 (numStars星星数量)(stepSize每次选择的不输)(rating当前所选择星星的数量)(isIndicator是否是)--> <RatingBar android:id="@+id/ratingBar2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numStars="6" android:stepSize="1" android:layout_gravity="center"/></LinearLayout>
阅读全文
0 0
- Android控制之ToggleButton和Switch与RatingBar
- Android学习之RatingBar,SeekBar,ToggleButton,Switch
- Android—ToggleButton、Switch和RatingBar使用
- Android开发-ToggleButton-Switch-RatingBar-AndroidStudio
- Android ToggleButton和Switch
- AnalogClock、ToggleButton、Switch、RatingBar、SeekBar
- ToggleButton,Switch,RatingBar的使用
- Android中ToggleButton,Switch,SeekBar,RatingBar的一些用法
- Android控件之ToggleButton、Switch
- widgets之switch和ToggleButton
- Android控件ToggleButton和Switch
- Android Switch和ToggleButton类
- Android之RadioButton与RadioGroup,CheckBox,Switch,ToggleButton的介绍
- Android UI之选择器-ToggleButton、Switch、CheckBox和RadioButton
- Android学习路之开关按钮ToggleButton和开关Switch
- 用户界面View之Switch与ToggleButton
- Android基础控件 - ToggleButton与Switch
- Android UI控件之ToggleButton、Switch
- Hibernate第一天
- 解决android.os.NetworkOnMainThreadException
- linux常用命令(logout,alias,clear,history,wc)
- Activemq实例
- 运行Tomcat时报java.lang.UnsupportedClassVersionError: oracle/demo/oow/bd/ui/IsUserLogued
- Android控制之ToggleButton和Switch与RatingBar
- Swift
- EularProject 74:Digit factorial chains
- python 记录,防止遗忘
- iframe有哪些缺点?应该怎么合理使用?
- Mac电脑上配置Java开发环境
- log4js 日志模块
- 达夫设备(Duff`s Device)减少迭代次数
- Angular CLI 使用教程指南参考