【问题标题】:How to open a custom popup programmatically in android?如何在android中以编程方式打开自定义弹出窗口?
【发布时间】:2011-11-11 11:06:48
【问题描述】:

我有一个简单的 android 应用程序可以进行搜索。我有一个自定义弹出窗口来选择过滤器。

我现在正在为此开发一个主屏幕应用小部件。该应用小部件类似于适用于 Android 的 Google 搜索小部件。

有一个过滤器弹出,一个搜索框(假的)和一个搜索按钮(而不是谷歌的语音按钮)。

除了弹出窗口外,一切都很好。

当在小部件上单击过滤器按钮时,我会触发一个带有额外指示的意图,指示单击了主页按钮。

当活动打开时,我会在应该打开弹出窗口的按钮上检查额外内容和 performClick()。但这行不通。任何想法?

我的代码是这样的 -

在我拥有的小部件中 -

Intent intent = new Intent(context, ActivityToOpen.class);

Bundle bundle = new Bundle();
bundle.putBoolean(CALL_FROM_WIDGET, true);
bundle.putBoolean(HOME_BUTTON_CLICKED, true);
intent.putExtras(loginBundle);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

在我的活动中 -

Bundle b = getIntent().getExtras();
if(b != null && b.getBoolean(CMWidget.HOME_BUTTON_CLICKED)) {
home_button.performClick();
}

我有一个类似这样的 onClickListener 设置 -

home_button = findViewById(R.id.home_button);
home_button.setOnClickListener(new OnClickListener() {

i have implemented onClick() here which pops up the custom popup menu. Popup menu has Quick Action Items.  

});

【问题讨论】:

  • 你能发布你的代码吗?没有代码很难找到问题。
  • 我用代码更新了问题。
  • 哥们,你已经发布了所有的代码,但没有发布有问题的代码。你是如何实现自定义弹出窗口的?可能有问题

标签: android android-widget


【解决方案1】:

我在找这个没人回复的。

Bundle b = getIntent().getExtras();
if(b != null && b.getBoolean(CMWidget.HOME_BUTTON_CLICKED)) {
findViewById(R.id.anchor_button).post(new Runnable() {
            @Override
            public void run() {
                showPopup();
            }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多