android - iPhone 和 Android 上的 CSS 悬停状态

标签 android css iphone hover tap

在移动设备上,我想使用 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/

相关文章:

iphone - 应用程序可以在 iPhone 上运行,但不能在 iPod Touch 上运行

android - 无法解析任何依赖项导入

HTML/CSS 关闭按钮与右/上 Angular 重叠

java - onPreExecute方法没有被调用

html - 为什么 css\html 代码在不同的主机中表现不同?

javascript - 在创建新 View 时在相似 View 上使用类而不是 id

iphone - Xcode 4 : Missing File's Owner with Storyboard?

iphone - 通过 HTTP Live Streaming 从 MP3 中提取 ID3 标签

java - 蓝牙设备(主)启动与 Android 的蓝牙连接

java - 从 Javascript 调用 Java 方法