SeekBar 滚动条
原seek_thumb样式----------------------------------------------------------------------↑↑↑↑↑
android:thumb="@drawable/my_thumb"
改写my_thumb.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?xml version= "1.0" encoding= "utf-8" ?> <selector xmlns:android= "http://schemas.android.com/apk/res/android" > <item android:state_pressed= "true" android:state_window_focused= "true" android:drawable= "@drawable/select" /> <item android:state_focused= "true" android:state_window_focused= "true" android:drawable= "@drawable/select" /> <item android:state_selected= "true" android:state_window_focused= "true" android:drawable= "@drawable/select" /> <item android:drawable= "@drawable/normal" /> </selector> |
Acitivity.class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener{ private SeekBar seekBar; private TextView text1; private TextView text2; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); seekBar = (SeekBar) findViewById(R.id.seekbar); seekBar.setOnSeekBarChangeListener( this ); text1 = (TextView) findViewById(R.id.txt1); text2 = (TextView) findViewById(R.id.txt2); } //数值改变 @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { text1.setText( "正在拖动" ); text2.setText( "当前数值" + progress); } //开始拖动 @Override public void onStartTrackingTouch(SeekBar seekBar) { text1.setText( "开始拖动" ); } //停止拖动 @Override public void onStopTrackingTouch(SeekBar seekBar) { text1.setText( "停止拖动" ); } |
Acitivity.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <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" tools:context= ".MainActivity" > <SeekBar android:thumb= "@drawable/my_thumb" android:id= "@+id/seekbar" android:max= "100" android:progress= "50" android:layout_width= "match_parent" android:layout_height= "wrap_content" /> <TextView android:layout_below= "@id/seekbar" android:id= "@+id/txt1" android:layout_width= "match_parent" android:layout_height= "wrap_content" /> <TextView android:layout_below= "@id/txt1" android:id= "@+id/txt2" android:layout_width= "match_parent" android:layout_height= "wrap_content" /> </RelativeLayout> |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· C# 13 中的新增功能实操
· Ollama本地部署大模型总结
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(4)
· langchain0.3教程:从0到1打造一个智能聊天机器人
· 用一种新的分类方法梳理设计模式的脉络