使用onConfigurationChanged在Android上设置TabHost empty
我对OnConfiguration Changed和TabHost有问题。 由于我的活动在轮换时重新启动,我发现这篇文章非常有用: 我将gui元素排序到函数InitialGui()中 重写onConfigurationChanged并调用InitialGui() 内部AndroidManifest使用onConfigurationChanged在Android上设置TabHost empty,android,rotation,android-tabhost,onconfigurationchanged,Android,Rotation,Android Tabhost,Onconfigurationchanged,我对OnConfiguration Changed和TabHost有问题。 由于我的活动在轮换时重新启动,我发现这篇文章非常有用: 我将gui元素排序到函数InitialGui()中 重写onConfigurationChanged并调用InitialGui() 内部AndroidManifest <activity android:label="@string/app_name" android:name=".MyAndroidAppActivi
<activity
android:label="@string/app_name"
android:name=".MyAndroidAppActivity"
android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="keyboardHidden|orientation"
>
我的问题是旋转后的空选项卡主机,单击开关选项卡没有任何显示。有什么提示吗?
感谢我认为很复杂,没有必要设置ContentView(R.layout.myLayout);或者别的什么。只需通过重写OnConfiguration Changed来防止调用onCreate方法
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}
这对我很有用。因为您在选项卡中使用了意图,并且活动(通过使用当前活动中不存在的意图启动)数据不会存储在返回的对象中(仅包含选项卡主机活动数据),但为什么要在第一次启动这些意图?没有更多的代码了。类似意向i=新意向(此,cls);星触觉(i);重新启动所有线程
<activity
android:label="@string/app_name"
android:name=".MyAndroidAppActivity"
android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="keyboardHidden|orientation"
>
public void InitialGui()
{
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setup();
// Android tab
Intent intentAndroid = new Intent().setClass(this, AndroidActivity.class);
TabSpec tabSpecAndroid = tabHost
.newTabSpec("Android")
.setIndicator("Android")
.setContent(intentAndroid);
// Apple tab
Intent intentApple = new Intent().setClass(this, AppleActivity.class);
TabSpec tabSpecApple = tabHost
.newTabSpec("Apple")
.setIndicator("Apple")
.setContent(intentApple);
// Windows tab
Intent intentWindows = new Intent().setClass(this, WindowsActivity.class);
TabSpec tabSpecWindows = tabHost
.newTabSpec("Windows")
.setIndicator("Windows")
.setContent(intentWindows);
// Blackberry tab
Intent intentBerry = new Intent().setClass(this, BlackBerryActivity.class);
TabSpec tabSpecBerry = tabHost
.newTabSpec("Berry")
.setIndicator("Berry")
.setContent(intentBerry);
// add all tabs
tabHost.addTab(tabSpecAndroid);
tabHost.addTab(tabSpecApple);
tabHost.addTab(tabSpecWindows);
tabHost.addTab(tabSpecBerry);
//set Windows tab as default (zero based)
tabHost.setCurrentTab(2);
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}