Android开发-ToggleButton-Switch-RatingBar-AndroidStudio
2016-12-12 17:15
411 查看
转载请注明出处:http://blog.csdn.net/iwanghang/
我正在参加CSDN 2016博客之星评选,希望得到您的宝贵一票~
http://blog.csdn.net/vote/candidate.html?username=iwanghang
请为我投票,谢谢 ~~
如果没有CSDN账号 直接使用微信/QQ/微博登陆 就能投票了~~
直接看GIF效果图和代码:
MainActivity.java:
这里是资源文件:
转载请注明出处:http://blog.csdn.net/iwanghang/
欢迎移动开发爱好者交流
沈阳或周边城市公司有意开发Android,请与我联系
联系方式
微信:iwanghang
QQ:413711276
邮箱:iwanghang@qq.com
我正在参加CSDN 2016博客之星评选,希望得到您的宝贵一票~
http://blog.csdn.net/vote/candidate.html?username=iwanghang
请为我投票,谢谢 ~~
如果没有CSDN账号 直接使用微信/QQ/微博登陆 就能投票了~~
直接看GIF效果图和代码:
MainActivity.java:
Public class MainActivity extends AppCompatActivity { private ToggleButton toggleButton; private Switch switch1; private RatingBar ratingBar; private ImageView imageView; public static final String TAG = "MainActivity"; private DynamicButton mButton; private DynamicButton mButtonTwo; private ProgressButton mProgressButton; private int value = 1; private Timer mTimer = new Timer(); int progress = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toggleButton = (ToggleButton) findViewById(R.id.toggleButton); switch1 = (Switch) findViewById(R.id.switch1); ratingBar = (RatingBar) findViewById(R.id.ratingBar); imageView = (ImageView) findViewById(R.id.imageView); toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b){ Toast.makeText(MainActivity.this, "开", Toast.LENGTH_SHORT).show(); imageView.setImageResource(R.drawable.off); }else { Toast.makeText(MainActivity.this, "关", Toast.LENGTH_SHORT).show(); imageView.setImageResource(R.drawable.on); } } }); switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b){ Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_SHORT).show(); }else { Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show(); } } }); ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float v, boolean b) { if (b){ Toast.makeText(MainActivity.this, "当前评分为" + v + "颗星", Toast.LENGTH_SHORT).show(); } } }); } }activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context="com.iwanghang.buttondemo.MainActivity"> <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#ff0000" android:text="这是一个ToggleButton: \n text属性无效 只可以设置textOn/textOff"/> <ImageView android:id="@+id/imageView" android:src="@drawable/off" android:layout_width="wrap_content" android:layout_height="225dp" android:layout_centerHorizontal="true" /> <ToggleButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="New ToggleButton" android:textOn="开" android:textOff="关" android:checked="true" android:id="@+id/toggleButton" /> <!--我是分割--> <ImageView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#000000" /> <TextView android:id="@+id/tv_2" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#ff0000" android:text="这是一个Switch: \n text属性在左边显示 也可以设置textOn/textOff"/> <Switch android:layout_width="match_parent" android:layout_height="wrap_content" android:text="New Switch" android:id="@+id/switch1" android:textOn="确定" android:textOff="取消" /> <!--我是分割--> <ImageView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#000000" /> <TextView android:id="@+id/tv_3" android:layout_below="@+id/switch1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#ff0000" android:text="这是一个RatingBar: \n numStars属性:星星数量 \n rating属性:默认选中数量 \n stepSize属性:步长 \n isIndicator属性:为true时,表示为指示器,不能选择几颗星"/> <RatingBar android:id="@+id/ratingBar" android:isIndicator="false" android:layout_below="@+id/tv_3" android:numStars="5" android:rating="3" android:stepSize="0.5" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <!--我是分割--> <ImageView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#000000" /> </LinearLayout> </ScrollView> </RelativeLayout>
这里是资源文件:
转载请注明出处:http://blog.csdn.net/iwanghang/
欢迎移动开发爱好者交流
沈阳或周边城市公司有意开发Android,请与我联系
联系方式
微信:iwanghang
QQ:413711276
邮箱:iwanghang@qq.com
相关文章推荐
- Android开发-ToggleButton-Switch-RatingBar-AndroidStudio
- Android开发总结笔记 ToggleButton和Switch(开关) 1-1-14
- Android—ToggleButton、Switch和RatingBar使用
- Android用户界面开发(23):RatingBar
- 【Android 开发】:UI控件之 RatingBar 评分控件的使用
- Android开发配置AndroidStudio和Eclipse之遇坑填坑
- 6.Android之switch和togglebutton按钮学习
- 【Android 开发教程】Button,ImageButton,EditText,ChcekBox,ToggleButton,RadioButton
- 【Android】AndroidStudio开发遇到的大坑以及填坑方法收集
- mac开发android之环境搭建--AndroidStudio
- Android基础控件ToggleButton→ Switch→ SeekBar→ProgressBar 控件
- Android开发 用AndroidStudio开发百度地图Demo时的经典错误230的另一种可能
- Android_Button(ImageButton,RadioButton,ToggleButton,Switch)详解
- Android开发:自定义的RatingBar图标显示不全的解决方案
- SeekBar 和RatingBar --MarsChen Android 开发教程学习笔记
- Android开发总结笔记 RatingBar(评分条) 1-1-12
- 【Android 开发】:UI控件之开关状态按钮 ToggleButton 的使用方法
- Android开发之星级评分条-RatingBar
- Android开发自学笔记—1.1(番外)AndroidStudio常用功能介绍
- 分享Android开发自学笔记之AndroidStudio常用功能