我们昨天讲到
按钮事件有分很多种
1.点击一下事件
2.长按事件
上一篇我们已经学会了按钮的点击一下事件
今天我们要更进阶一咪咪
来学第2个按钮的事件
按钮长按事件
长按这功能也很常用的到
比如:计算机长按归零、长按预览讯息
这些都是常按的范畴
那我们废话不多说
今天我们一样搭配Log来验证长按功能是否正确
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
<Button
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="158dp"
android:layout_marginTop="237dp"
android:layout_marginEnd="159dp"
android:text="长按"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Log.v("one","长按" );
执行结果:
你会发现按一下没有反应,要按住不放Logcat才会显示one : 长按
<<: 电子书阅读器上的浏览器 [Day23] 双视窗可拖拉调整大小元件
今天教大家一个简单免费的方式来享受YouTube後台播放。 只需 3 个简单的步骤,即可在 iOS ...
假使设定HTML: <div class="container"> ...
在上一篇我们看到,即便我们能不写程序就设定一些自动回覆,仍然相当麻烦,如果需要的功能更多,更无法应付...
模板方法 Template Method 模板方法,是一种如果这包水泥我有、你也有,就连乔瑟夫都有...
在认识动态规划之前先来理解Divide and Conquer(分治法)吧!Divide and ...