button的操作
来源:互联网 发布:浪潮软件集团招聘 编辑:程序博客网 时间:2024/05/18 02:34
1. 对button按钮的抬起 按下的一些操作一级监听//在xml中写button布局<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.bwie.activity.MainActivity"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="onclick" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" android:background="@drawable/onclick" /></android.support.constraint.ConstraintLayout>//在main方法中进行触摸监听以及获取idpublic class MainActivity extends AppCompatActivity { private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.button); Buttonlister buttonlister=new Buttonlister(); button.setOnTouchListener(buttonlister); } class Buttonlister implements View.OnTouchListener{ @Override public boolean onTouch(View view, MotionEvent motionEvent) { switch (view.getId()){ case R.id.button: if(motionEvent.getAction()==MotionEvent.ACTION_UP){ Toast.makeText(MainActivity.this,"抬起",Toast.LENGTH_SHORT).show(); // button.setBackgroundColor(Color.GREEN); }else if(motionEvent.getAction()==MotionEvent.ACTION_DOWN){ Toast.makeText(MainActivity.this,"按下",Toast.LENGTH_SHORT).show(); // button.setBackgroundColor(Color.RED); } break; } return false; } }}
阅读全文
0 0
- button的操作
- 针对单个Button的操作
- WebView 的button多操作
- 关于button按钮的操作
- MFC Radio Button 和 Combox Button的简单操作
- DataGrid关于button的相关操作
- Button基础操作
- Button多选操作
- Matalb GUI 中toggle button和raido的操作
- c#操作通过button控制viewtree节点的改变
- Android 基础的Button类对象操作(OnClickListener)
- 如何阻止button默认的刷新页面操作
- Button---圆角的Button
- DataGrid中使用Button操作
- [Button]几个漂亮的Button的CSS
- 1.label的基本操作,通过点击按钮Button改变label的属性
- Button或其它控件的双击或者多击的操作
- <button ></button>与<input type="button" />的区别
- 分布式电商项目实战
- Eclipse Sdk Manager 下载太慢好办法
- java解压缩文件
- Java 几道常见String面试题
- sqlplus 导出excel&html
- button的操作
- Lua 加载函数require dofile loadfile
- 矩阵快速幂
- 优雅的在通用Adapter的item内部控件监听事件
- HTML5获取地理位置信息
- 设置TextView文本支持长按复制粘贴
- 详说css与预处理器(以及less、sass、stylus的区别)
- 安卓相机使用代码
- 刚开通微博。。。。WEBview设置