Android基础控件ToggleButton→ Switch→ SeekBar→ProgressBar 控件

Android基础控件ToggleButton→  Switch→ SeekBar→ProgressBar  控件

后续还有很多用法,再补充

ToggleButton →关闭声音按钮

java.lang.Object
  android.view.View
     android.widget.TextView
        android.widget.Button
           android.widget.CompoundButton
        android.widget.ToggleButton

Switch →开关,且能滑动

java.lang.Object
  android.view.View
     android.widget.TextView
        android.widget.Button
           android.widget.CompoundButton
              android.widget.Switch

SeekBar→实现滑动星级评价

java.lang.Object
  android.view.View
    android.widget.ProgressBar
      android.widget.AbsSeekBar
        android.widget.SeekBar

ProgressBar →页面加载效果  注意与ProgressDialog 的区别

java.lang.Object
  android.view.View
    android.widget.ProgressBar


→main.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >

    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="ToggleButton"
            />


    <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textOn="声音开启"
            android:textOff="声音关闭"
            />
    <!--android 4.0版本之后,Android sdk中
   又新加入了一个新的表示开关的控件Switch,不但能表示开关的功能,而且可以实现滑动开关
   -->
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Switch"
            />
    <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textOn="声音开启"
            android:textOff="声音关闭"
            />
    <!--SeekBar控件用来实现滑动效果:实现滑动控制音量
    设置max代表SeekBar最大时的数值
    设置progress属性,代表在滑动过程中最小的滑动距离
    拓展:
    progressDrawable:设置拖动条的样式
    thumb:设置SeekBar中滑块的图片
    secondaryProgress:代表第二进度条的大小
    等等属性-->
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="SeekBar"
            />
    <SeekBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:max="100"
            android:progress="2"
            />
    <!--RatingBar控件用来实现滑动进行星级评价的效果
    numStars属性,代表显示最大的星级数量
    stepSize属性,代表在评价过程中最小的移动单位
    style:设置RatingBar的样式
    rating:设置RatingBar的默认评分
    isIndicator:设置RatingBar是否是一个指示器,如果是的,用户就无法进行修改了
    等等
    -->
 <!--ProgressBar实现页面加载效果,
    Widget.ProgressBar.Horizontal:水平ProgressBar的进度条效果
    Widget.ProgressBar.Large:大圆形的进度条效果
    Widget.ProgressBar.Small:小圆形的进度条效果
    Widget.ProgressBar.Inverse:普通进度条翻转
    Widget.ProgressBar.Large.Inverse:大进度条翻转
    Widget.ProgressBar.Small.Inverse:小进度条翻转
    -->
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="RatingBar"
            />
    <RatingBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numStars="5"
            android:stepSize="0.5"
            />
    <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@android:style/Widget.ProgressBar"
            />
   
</LinearLayout>



→Java代码
package com.ncsyeyy.YeyyToggleButton;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;


public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
//        注意:ProgressDialog不同于ProgressBar,在加载的过程中,ProgressBar是铜鼓按键无法取消的,
//        而ProgressDialog运行过程中按手机物理返回键,就可以消失。而且ProgressDialog不是一个控件类,
//        而是作为android.app包中的一个应用类来使用。
        //定义ProgressDialog对象
        ProgressDialog pd=new ProgressDialog(this);
        //设置pd的标题信息
        pd.setTitle("程序正在加载中……");
        //调用pd的show方法显示此ProgressDialog
        pd.show();
    }
}



源码地址:http://download.csdn.net/detail/csdnyuandaimaxuexi/9105421

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值