gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:41:03 32 4
gpt4 key购买 nike

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

我已经尝试在 Presentation 布局上添加一个按钮并在 ClickListener 上注册一个按钮,但它似乎不起作用。还有别的办法吗?

这是我的代码:

在我的演示课上

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说:

A presentation is a special kind of dialog whose purpose is to present content on a secondary display. A Presentation is associated with the target Display at creation time and configures its context and resource configuration according to the display's metrics.

所以我认为Android Presentation可以像Dialog一样处理touche事件。这里我会告诉你Dialog是如何处理touch事件的。

第一步

创建您的自定义布局 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>

第二步

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);

关于android - Android Presentation 可以处理触摸事件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44103992/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com