实例1:实现跟踪鼠标单击状态的图片按钮
来源:互联网 发布:ubuntu 16.04卸载qq 编辑:程序博客网 时间:2024/04/30 08:44
1、布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".MainActivity" android:orientation="vertical" android:gravity="center"> <ImageView android:id="@+id/start" android:background="#000" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>
2、编写Drawable资源对应的XML文件button_state.xml,用于设置当鼠标按下时显示的图片和鼠标设置没有按下时显示的图片
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/start_a"/> <item android:state_pressed="false" android:drawable="@drawable/start_b"/> </selector>
3、为main.xml布局文件中的图片按钮设置android:src属性
android:src = "@drawable/button_state"
4、在主活动中获取添加的图片按钮,并为其添加鼠标单击事件监听器
<span style="font-size:12px;">ImageView imageView = (ImageView)findViewById(R.id.start); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this,"开始",Toast.LENGTH_SHORT).show(); } });</span>
0 0
- 实例1:实现跟踪鼠标单击状态的图片按钮
- 【Android开发】范例1-实现跟踪鼠标单击状态的图片按钮
- 自己写的鼠标单击按钮实现图片切换
- .NET 图片按钮单击事件的实现
- Qt5.8 按钮跟踪鼠标状态
- Android - ImageButton单击切换按钮图片效果的实现
- Android - ImageButton单击切换按钮图片效果的实现
- Android - ImageButton单击切换按钮图片效果的实现
- Android - ImageButton单击切换按钮图片效果的实现 .
- Android - ImageButton单击切换按钮图片效果的实现 .
- Android - ImageButton单击切换按钮图片效果的实现
- Android - ImageButton单击切换按钮图片效果的实现
- Android - ImageButton单击切换按钮图片效果的实现
- selector使用与ImageButton单击按钮图片效果的实现
- Android - ImageButton单击切换按钮图片效果的实现
- 模拟鼠标单击某按钮
- Android的按钮单击事件及监听器的实现方式(附实例)
- 在TBitBtn钮上单击鼠标,然后放开鼠标,按钮能保持按下状态,再次单击,能恢复成弹起状态?
- Chrome的bug解决办法:overflow导致a标签无法显示
- 宜信旗下网络P2P平台宜人贷在美国纽交所上市
- 数据库schema设计与优化
- myeclips 2015 激活
- linux监控命令
- 实例1:实现跟踪鼠标单击状态的图片按钮
- android多国语言包命名规则
- Linux心跳---HZ
- Xcopy命令参数使用介绍
- OpenCV版本向下兼容
- spark on yarn图形化任务监控利器:History-server帮你理解spark的任务执行过程
- Java 多线程 并发编程
- java.lang.Runtime类总结
- 一个简单大气的登陆(login)界面源码介绍学习