以下是代码:
公共类MenuTabActivity扩展TabActivity实现了OnTabChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_layout);
TabHost tb = getTabHost();
TabHost.TabSpec spec = null;
Intent intent = null;
// My Profile tab
intent = new Intent(this, MyProfileActivityGroup.class);
View myProfileView = LayoutInflater.from(this).inflate(R.layout.button_profil, null);
spec = tb.newTabSpec("0").setIndicator(myProfileView).setContent(intent);
tb.addTab(spec);
// Driving tab
intent = new Intent(this, DrivingActivityGroup.class);
View drivingView = LayoutInflater.from(this).inflate(R.layout.button_conduite, null);
spec = tb.newTabSpec("1").setIndicator(drivingView).setContent(intent);
tb.addTab(spec);
// Score Tab
intent = new Intent(this, ScoreActivityGroup.class);
View scoreView = LayoutInflater.from(this).inflate(R.layout.button_score, null);
spec = tb.newTabSpec("2").setIndicator(scoreView).setContent(intent);
tb.addTab(spec);
// Advices Tab
intent = new Intent(this, AdvicesActivity.class);
View advicesView = LayoutInflater.from(this).inflate(R.layout.button_conseils, null);
spec = tb.newTabSpec("3").setIndicator(advicesView).setContent(intent);
tb.addTab(spec);
tb.setOnTabChangedListener(this);
Main.tabBar = tb;
tb.setCurrentTab(0);
}
@Override
public void onTabChanged(String tabId) {
if (tabId.equals("2")){
//refresh third tab
((ScoreActivityGroup)(getLocalActivityManager().getActivity(tabId))).getScoreActivity().updateView();
}
if (tabId.equals("1")){ //driving activity
if (Utils.tabImage == null) {
//create the static image of the tabbar here
Bitmap tabImage = Bitmap.createBitmap(getTabHost().getTabWidget().getWidth(), getTabHost().getTabWidget().getHeight(), Bitmap.Config.RGB_565);
getTabHost().getTabWidget().draw(new Canvas(tabImage));
Utils.tabImage = tabImage;
}
//load second "tab" Activity
((DrivingActivityGroup)(getLocalActivityManager().getActivity("1"))).startDrivingActivity();
}
if (!tabId.equals("2")){
if (getLocalActivityManager().getActivity("2") != null){
if (((ScoreActivityGroup)getLocalActivityManager().getActivity("2")).getCurrentActivity() instanceof ScoreDetailsActivity){
//dismiss Conseil Dialog if it exists
((ScoreDetailsActivity)(((ScoreActivityGroup)getLocalActivityManager().getActivity("2")).getCurrentActivity())).dismissConseilDialog();
}
}
}
}
/**
* This method starts an activity with a given animation (ex: bottom-top)
* Used for info activities
*
* This action is placed here because the animations are ignored if done
* from child activities of the MenuTabActivity.
*
* @param clazz
* @param enterAnim
* @param exitAnim
* @param intentExtra
*/
public void startActivityWithOverridePendingTransition(Class<?> clazz, int enterAnim, int exitAnim, Integer intentExtra){
final Intent intent = new Intent(this, clazz);
if ( intentExtra != null ){
intent.putExtra("com.renault.Intent", intentExtra);
}
startActivity(intent);
overridePendingTransition(enterAnim, exitAnim);
}
public void onDestroy(){
super.onDestroy();
if (Main.monitoringHasStarted) {
Main.DriveBusinessService.stopMonitoring();
ScoringModelPojo.saveToBundle(getApplicationContext());
}
Main.monitoringHasStarted = false;
SettingsModel.saveToBundle(getApplicationContext());
}
} `
这是tabwidget:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight = "1"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background = "@color/grayFond"
android:layout_weight = "0"/>
</LinearLayout>
</TabHost>
你们有没有遇到过标题中提到的问题?
答案 0 :(得分:0)
我发现了什么问题。它一定是个bug。在清单文件中,我没有状态栏和全屏。将状态栏重新引入屏幕时,(NO FULLSCREEN)它可以正常工作。也许这有助于某人。
PS。这应该作为ANDROID的错误提交。 (在2.1中测试)