自定义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

示例代码下载:

更多相关文章

  1. Android与Javascript交互示例(一)
  2. android音频播放简单示例
  3. Android和iPhone应用程序界面布局示例
  4. Android列表控件Spinner简单用法示例
  5. Android ApiDemos示例解析(91):OS->SMS Messaging
  6. Android 使用Loader示例

随机推荐

  1. Android——播放器和图片轮播
  2. Android极光推送jPush混淆解决方案终极篇
  3. Android 漂亮的 Dialog (弹出框)
  4. Android添加一个回调监听接口
  5. Android代码性能优化技巧
  6. android的入门学习
  7. 尝试在安卓系统中获得USSD响应
  8. Cocos2d-x 3.0 开发(十七)使用Cocos2d-x 3.
  9. Android源码在UBUNTU编译全过程
  10. 空对象引用错误:使用SQLite的Android Stud