android之SeekBar控件用法详解
程序员文章站
2024-03-05 19:19:13
mainactivity.java
package com.example.mars_2400_seekbar;
import android.suppor...
mainactivity.java
package com.example.mars_2400_seekbar; import android.support.v7.app.actionbaractivity; import android.support.v7.app.actionbar; import android.support.v4.app.fragment; import android.app.activity; import android.os.bundle; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.seekbar; import android.widget.seekbar.onseekbarchangelistener; import android.widget.textview; import android.os.build; public class mainactivity extends activity implements onseekbarchangelistener { private textview tv; private seekbar sb; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); tv = (textview) findviewbyid(r.id.textview1); sb = (seekbar) findviewbyid(r.id.seekbar); sb.setonseekbarchangelistener(this); } @override public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) { // todo auto-generated method stub tv.settext("progress is " + progress + (fromuser ? " trigger" : " nontrigger") + " by user."); } @override public void onstarttrackingtouch(seekbar seekbar) { // todo auto-generated method stub system.out.println("onstart-->"+seekbar.getprogress()); } @override public void onstoptrackingtouch(seekbar seekbar) { // todo auto-generated method stub system.out.println("onstop-->"+seekbar.getprogress()); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate the menu; this adds items to the action bar if it is present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
activity_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:id="@+id/textview1"/> <seekbar android:id="@+id/seekbar" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </linearlayout>
以上就是小编为大家带来的android之seekbar控件用法详解的全部内容了,希望对大家有所帮助,多多支持~
上一篇: JDK、J2EE、J2SE、J2ME四个易混淆概念区分
下一篇: 让Java代码更高效
推荐阅读
-
Java中的instanceof关键字在Android中的用法实例详解
-
Java中的instanceof关键字在Android中的用法实例详解
-
详解JDK 5 Annotation 注解之@Target的用法介绍
-
详解JDK 5 Annotation 注解之@Target的用法介绍
-
详解Android开发之MP4文件转GIF文件
-
Java编程中的条件判断之if语句的用法详解
-
Android开发之ListView、GridView 详解及示例代码
-
Android UI设计之AlertDialog弹窗控件
-
Android开发进阶自定义控件之滑动开关实现方法【附demo源码下载】
-
详解Android业务组件化之URL Schema使用