HOWTO触发一个事件,当有人点击在屏幕任意位置上的Andr​​oid应用程序? [英] howto fire a event when someone click anywhere on the screen in a android app?

查看:118
本文介绍了HOWTO触发一个事件,当有人点击在屏幕任意位置上的Andr​​oid应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能当有人点击该应用程序的某个地方活动?

how can i get the event when someone click somewhere in the app?

是并不重要,如果有一个按钮什么的。

is does not matter if there is a button or something.

我只是想申请一个onclick事件侦听整个应用程序的屏幕上。

i just want to apply a onclick event listener on the whole application screen.

如何做到这一点?

推荐答案

setonclicklistner 为您的布局文件的主要布局....

setonclicklistner for main layout of your layout file....

像.... main.xml中

Like....main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/mainlayout">
 <!- Your other view->
</Relativelayout>

和设置点击监听mainlayout ...

and set click listener for mainlayout...

 RelativeLayout rlayout = (RelativeLayout) findViewById(R.id.mainlayout);
 rlayout.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

    }

 });

这篇关于HOWTO触发一个事件,当有人点击在屏幕任意位置上的Andr​​oid应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆