在移动设备上,我想使用 CSS 悬停状态。
我发现在iPhone/iPad上,用户第一次点击结果悬停状态,第二次点击产生点击事件。
太完美了。
我想在 Android 上使用同样的东西。
第一次点击 - 悬停状态 第二次点击 - 点击事件
提前谢谢你。
最佳答案
添加GestureDetector.SimpleOnGestureListener让 View 检测单击和双击,并使用 onSingleTapConfirmed() 方法处理悬停状态,使用 onDoubleTap() 方法处理点击事件。
或者您可以在检测到点击时使用计数,并对每个计数执行不同的方法。
在onCreate方法外全局声明一个变量:
//Declaring the variable to count the number of clicks
int count = 0;
然后在 onCreate 方法中实现以下内容。在这里,我们在 Button 上设置一个 OnClickListener:
// Declaring the Button and Type Casting it.
Button btn1 = (Button) findViewById(R.id.button1);
// Setting OnClickListener on btn1
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//Executing the following code on the click
//Incrementing the variable count by 1 on the click of the button
count++;
//Displaying the count using a Toast Toast.makeText(MainActivity.this,
"The button has been clicked " + count + " times",Toast.LENGTH_SHORT).show();
}
});
关于android - iPhone 和 Android 上的 CSS 悬停状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22231198/