- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 MapActivity 作为 TabActivity 中的四个选项卡之一。这个 MapActivity 可以启动一个 PopupWindow,它是一个图例。 PopupWindow 保留在屏幕上的 map 顶部,直到再次单击“显示图例”按钮(来回等)。
问题是,当用户切换到另一个选项卡时,PopupWindow 在 View 上保持不变。
我试过在 MapActivity 类中实现 onPause() 方法,然后从那里关闭它。使用此方法时应用力关闭。
有什么帮助吗?谢谢!
编辑:这是我的一些代码:
在 MainActivity 中,它建立了四个选项卡:
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, FirstActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("game").setIndicator("First",
res.getDrawable(R.drawable.ic_tab_game))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, SecondActivity.class);
spec = tabHost.newTabSpec("alerts").setIndicator("Second",
res.getDrawable(R.drawable.ic_tab_alert))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MapActivity.class);
spec = tabHost.newTabSpec("map").setIndicator("Map",
res.getDrawable(R.drawable.ic_tab_map))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, LastActivity.class);
spec = tabHost.newTabSpec("experience").setIndicator("Last",
res.getDrawable(R.drawable.ic_tab_experience))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
现在在我的 MapActivity 类中(它扩展了 MapActivity):
// Declare the Legend PopupWindow
mapLegendInflater = (LayoutInflater) MapActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mapLegendPopupLayout = mapLegendInflater.inflate(
R.layout.maptablegendpopuplayout, null, false);
mapLegendPopup = new PopupWindow(mapLegendPopupLayout,
(int) (0.45 * getApplicationContext().getResources()
.getDisplayMetrics().widthPixels),
(int) (0.33 * getApplicationContext().getResources()
.getDisplayMetrics().heightPixels), true);
mapLegendPopup.setFocusable(false);
mapLegendPopup.setOutsideTouchable(true);
Boolean legendIsShown = false;
mapLegendButton = (Button) findViewById(R.id.buttonMapLegend);
mapLegendButton.setOnClickListener(mapLegendListener);
private OnClickListener mapLegendListener = new OnClickListener() {
public void onClick(View v) {
// Launch or dismiss the map legend popup
if (legendIsShown) {
mapLegendPopup.dismiss();
mapLegendButton.getBackground().clearColorFilter();
legendIsShown = false;
} else {
mapLegendPopup.showAtLocation(
findViewById(R.id.buttonMapLegend), Gravity.TOP
| Gravity.LEFT, 8,
(int) (0.23 * getApplicationContext().getResources()
.getDisplayMetrics().heightPixels));
mapLegendButton.getBackground().setColorFilter(
new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));
// mapLegendButton.getBackground().setColorFilter(0xFFFFFF00,
// PorterDuff.Mode.MULTIPLY);
legendIsShown = true;
}
}
};
我希望这能让我了解我所处的位置。 map 选项卡上的一切都运行良好。只有当您显示图例并切换选项卡时,它仍会显示在其他 View 中。
最佳答案
我知道你说过实现 onPause() 对你不起作用,但我试过了,在 MapActivity 中实现 onResume() 和 onPause() 对我来说确实有用。
我需要在 onResume() 中执行 View.post(new Runnable() { ... }) 因为我无法在 onResume() 期间重新创建 popupWindow 所以我不得不安排它在之后立即发生:
package com.esri.android.tabdemo;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
public class MapActivity extends Activity
{
private TextView textView = null;
private PopupWindow popupWindow = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setText("Hello World from MapActivity");
setContentView(textView);
}
@Override
protected void onPause()
{
super.onPause();
if (popupWindow != null)
{
popupWindow.dismiss();
popupWindow = null;
}
}
@Override
protected void onResume()
{
super.onResume();
final Context context = this;
textView.post(
new Runnable()
{
public void run()
{
popupWindow = new PopupWindow(context);
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
Button button = new Button(context);
button.setText("Hello");
button.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(context, "Hello", Toast.LENGTH_SHORT).show();
}
});
linearLayout.addView(button);
popupWindow.setContentView(linearLayout);
popupWindow.showAtLocation(linearLayout, Gravity.LEFT | Gravity.BOTTOM, 10, 10);
popupWindow.update(256, 64);
}
}
);
}
}
关于android - 在 TabActivity 中切换到新选项卡时关闭 Android PopupWindow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4226898/
public class HMITabActivity extends TabActivity{ @Override protected void onCreate(Bundle saved
我正在测试 TabActivity,每个选项卡中都有一个列表。 在运行应用程序时,选项卡的内容会像这样重叠。 在我单击选项卡后,重叠被清除。这是我的代码: testtabs.xml 布局:
我正在开发一个使用 TabActivity 的 android 示例项目。但由于现在已弃用,我将其替换为“fragment ” Activity 。现在我不知道用什么来代替, TabHost tabH
我有一个 TabActivity,想要捕捉和处理 HOME 和 BACK 的按下。我需要在哪里捕捉这些事件? 在我的 TabActivity 子类中,我实现了以下内容: @Override publi
我正在尝试向我的 TabActivty 添加动画。例如,当用户选择第二个选项卡时,我希望新 Activity 来自右侧。当用户选择第一个选项卡时,我希望 Activity 来自左侧。 我找到了如何添加
我该如何解释我的问题? 我有一个使用选项卡的应用程序(通过 Intent ,而不是 View )。我已经在每个 View 内实现了导航,没有任何问题,但我需要在全屏和横向模式(因此没有标签)的 Act
我有一个托管其他三个 Activity 的 TabActivity。 如果选择了第一个选项卡,我可以更改设备方向,一切正常。 如果我转到第二个或第三个选项卡并更改方向,选项卡子 Activity 的(
我想知道使用 Fragments(ActivityGroup 的新版本)有什么好处至于现在我可以用 TabActivity 做同样的事情。如果我想替换固定的 tabwidget 我可以将可见性设置为
我有一个包含三个选项卡的 TabActivity。拳头标签是问题所在。第一个选项卡加载 ActivityGroup。 OnCreate 它加载默认内容 View 。稍后在某个事件上,我们添加了不同的内
我的主要 Activity 是 TabActivity。 我有一些由选项卡 Activity 呈现的 Activity ,我想将其锁定为纵向。 在 AndroidManifest.xml 中,当我为
TabActivity 中的问题我的应用程序中有三个选项卡,每个选项卡都是不同的 Activity 。在第一个选项卡中,我有一个文本字段和 ListView ,用户可以通过它们进行搜索但是在搜索之后当
我在 TabActivity 中创建了三个选项卡onCreate . 如何在运行时隐藏一个选项卡? 最佳答案 要隐藏选项卡,您必须将其从 TabWidget 中删除。仅仅设置 INVISIBLE 是不
这个主题可能看起来与其他主题相似,但我还没有找到任何适用于这种情况的答案。 这就是我想要的:我有一个带菜单的 TabActivity,其中包含没有任何菜单的选项卡。当我按下菜单按钮时,我希望显示唯一的
我是 Android 开发的新手,当我制作我的第一个应用程序时感到非常兴奋(并且我认为完全理解它),但我就是无法运行它。它对我来说看起来很干净,我不确定根据调试信息要查找什么。至少解释一下我应该寻找什
我正在开发一个使用 tabs 和 fragments 的应用程序。 Google 正在提供 android 支持 v4.jar,以便我们也可以使用 api 1.6 的 fragment 。 我已经查看
我搜索了我的具体问题,但找不到问题的答案。 在我的应用程序中,我的主要 Activity 有一个包含 3 个选项卡的选项卡主机。所有三个选项卡都有一个包含项目的 ListView 。 选项卡 1 Li
我在这里看到了一些类似的帖子,但我还没有找到任何答案。我想在我的选项卡 Activity 中添加滑动手势,以便我能够使用该手势更改选项卡。 这是我的代码: public class Domicilia
我的 TabActivity 有一个类 public class DashboardActivity extends TabActivity 这有几个选项卡和一个操作栏。这些选项卡之一是项目列表。 p
我正在尝试为应用程序实现以下背景... 对于背景图像(应用程序背景)...我在 setContentView(布局)中设置图像...通过添加此行,我收到运行时异常... 如果我在子 Activity
好吧,我正在使用 TabActivity 为 api 8 开发和应用程序但我今天发现“此类已弃用。” 所以我们应该使用FragmentActivity从现在开始实现标签?但是当我想显示带有 Activ
我是一名优秀的程序员,十分优秀!