zoukankan      html  css  js  c++  java
  • Android:自定义Dialog

    自定义Dialog:显示SeekBar

    效果图:

    image

     

    步骤:

    //SettingActivity.java
    button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sensorDialog = new SensorDialog(SettingActivity.this); //调用Dialog
                sensorDialog.show();
            }
        });
    //SensorDialog.java
    public class SensorDialog extends Dialog {
        private SeekBar mSeekBar;
        private TextView mProgressText;
        
        protected SensorDialog(Context context) {
            super(context);
        }
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            this.setContentView(R.layout.sensorprogress);
            
            mSeekBar = (SeekBar) findViewById(R.id.seek);  //取得SeekBar对象
             mProgressText = (TextView) findViewById(R.id.progress);
            
            mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
                @Override
                public void onStopTrackingTouch(SeekBar arg0) {
                }
                @Override
                public void onStartTrackingTouch(SeekBar arg0) {
                }    
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    mProgressText.setText("当前值:"+ Config.PROGRESS);
                }
            });
        }
    }
    //sensorprogress.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">
        
        <SeekBar
            android:id="@+id/seek"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:max="100" android:progress="50"
            android:secondaryProgress="75" />
    
        <TextView android:id="@+id/progress"
               android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="当前值:50" android:textSize="30sp" />
    </LinearLayout>

    参考链接:http://www.apkbus.com/forum.php?mod=viewthread&tid=13854

    示例代码下载:

  • 相关阅读:
    Entity Framework简介
    Java学习笔记-spring-Bean作用于
    Java学习笔记-spring-Bean实例化
    第四章--第二节:类
    为什么越来越少的人用jQuery
    年入50万的方法
    第一节--项目介绍和初始化
    第四章--第一节:函数
    第一节--API爬虫--环境设置与课程简介
    第三章--第六节:元祖
  • 原文地址:https://www.cnblogs.com/klcf0220/p/3278845.html
Copyright © 2011-2022 走看看