繁体   English   中英

Android Presentation可以处理触摸事件吗?

[英]Can Android Presentation handle touch events?

我知道Android 演示文稿可以有自己的布局,这意味着我可以创建按钮等UI组件。但是,有人知道演示文稿是否可以处理触摸事件吗?

我尝试在Presentation布局上添加按钮并在onClickListener上注册按钮,但它似乎无法正常工作。 还有另一种方法吗?

这是我的代码:

在我的演讲班

mHelloToast = (Button) findViewById(R.id.btn_presentation_hello_toast);
    mHelloToast.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast toast = Toast.makeText(getContext(), "hello presentation", Toast.LENGTH_SHORT );
            toast.show();
        }
    });

编辑:凹凸

Doc说:

演示是一种特殊的对话框,其目的是在辅助显示器上演示内容。 Presentation在创建时与目标Display关联,并根据Display的指标配置其上下文和资源配置。

所以我认为Android Presention可以像Dialog一样处理touche事件。在这里,我将向您展示Dialog如何处理touch事件。

第1步

创建您的自定义布局res/layout/dialog_signin.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/btn_presentation_hello_toast"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

第2步

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Get the view which you want to receive touch event
//// Pass null as the parent view because its going in the dialog layout
View rootView = inflater.inflate(R.layout.dialog_signin, null);
Button bt = (Button)rootView.findViewById(R.id.btn_presentation_hello_toast);
// set click or touch listener
bt.setOnClickListener(....);

// set dialog's contents
builder.setView(rootView);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM