面临标签活动的问题,我在五月有 5 个标签,我正在使用带有ACTION_VIEW意图播放 YouTube 视频的一个标签。当我第一次选择该选项卡时,它会打开浏览器并播放我的视频,但下次它没有响应我。我尝试了很多。如果您有任何解决方案,请与我分享。
这是代码形式 TabActivit
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setWindowAnimations(0);
tabHost = getTabHost();
tabHost.setup();
extras = getIntent().getExtras();
int isFetched = extras.getInt("IsFetched", 0);
Resources res = getResources();
Intent t0 = new Intent(this, HomeTabGroup.class);
t0.putExtra("IsFetched",isFetched);
tabHost.addTab(tabHost.newTabSpec("Home")
.setIndicator(prepareTabView(this, "0", res
.getDrawable(R.drawable.hometab)))
.setContent(t0));
tabHost.getTabWidget().setBackgroundResource(R.drawable.bg_nav);
// Intent t1 = new Intent(this, SurprizeMeTabGroup.class);
Intent t1 = new Intent(this, SurpriseScreen.class);
tabHost.addTab(tabHost.newTabSpec("surprise")
.setIndicator(prepareTabView(this, "1", res
.getDrawable(R.drawable.surprizetab)))
.setContent(t1));
tabHost.setCurrentTab(0);
HomeTabGroup.group.tabHost = this.tabHost;
以下是我的备份屏幕的代码
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.surprise_screen);
Intent intent = getYouTubeIntent(this, "http://www.youtube.com/watch?v=6KKXVbJCKEo");
startActivity(intent);
}
芬利 经过多次尝试,我找到了解决方案。覆盖由 TabActivity 扩展的类的 onchange 方法并调用ACTION_VIEW Intent
@Override
public void onTabChanged(String tabId) {
if(tabId.equals("surprise")) {
startActivity(getYouTubeIntent(MainTabbarScreen.this, "http://www.youtube.com/watch?v=6KKXVbJCKEo"));
}
}
});