タブレイアウトを設定するこのxmlがあります
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:id="@+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<!-- tabs are included dynamically from adapter -->
</FrameLayout>
</LinearLayout>
</TabHost>
これは私の活動です:
public class TabBackupRestoreActivity extends SuperActivity {
@Override View manageActivity() throws Exception {
return new TabBackupRestoreAdapter(this, this,savedInstanceState);
}
}
これはすべてのタブを管理するアダプターです。
public class TabBackupRestoreAdapter extends TabHost {
private static int TAB_HEIGHT=40;
TabHost thisView;
public TabBackupRestoreAdapter(Context context,ActivityGroup act,Bundle state) {
super(context);
thisView = (TabHost)inflate(getContext(), R.layout.tab_backup_restrore, this);
LocalActivityManager lam = act.getLocalActivityManager();
lam.dispatchCreate(state);
thisView.setup(lam);
addNewTab(R.string.backup,new Intent(getContext(),BackupActivity.class));
addNewTab(R.string.restore, new Intent(getContext(),RestoreActivity.class));
}
private void addNewTab(int stringId, Intent activity){
TabHost.TabSpec spec = thisView.newTabSpec(getContext().getString(stringId));
spec = spec.setContent(activity);
spec = spec.setIndicator(getContext().getString(stringId));
thisView.addTab(spec);
//modifico l'altezza del tab
int totalTabs = thisView.getTabWidget().getChildCount();
thisView.getTabWidget().getChildAt(totalTabs-1).getLayoutParams().height = TAB_HEIGHT;
}
}
andorid 2.2 まではすべて正常に動作しますが、このアプリを Android 4 で実行すると、次の例外がスローされます。
android.content.res.Resources$NotFoundException: Resource ID #0x0
android.content.res.Resources.getValue(Resources.java:1018)
android.content.res.Resources.loadXmlResourceParser(Resources.java:2105)
android.content.res.Resources.getLayout(Resources.java:857)
android.view.LayoutInflater.inflate(LayoutInflater.java:394)
android.widget.TabHost$LabelIndicatorStrategy.createIndicatorView(TabHost.java:531)
android.widget.TabHost.addTab(TabHost.java:223)
it.hyde.adapters.TabBackupRestoreAdapter.addNewTab(TabBackupRestoreAdapter.java:41)
it.hyde.adapters.TabBackupRestoreAdapter.<init>(TabBackupRestoreAdapter.java:31)
it.hyde.activities.TabBackupRestoreActivity.manageActivity(TabBackupRestoreActivity.java:9)
it.hyde.activities.SuperActivity.onCreate(SuperActivity.java:41)
android.app.Activity.performCreate(Activity.java:4465)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
android.app.ActivityThread.access$600(ActivityThread.java:123)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4424)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
dalvik.system.NativeStart.main(Native Method)
android4のライブラリでコンパイルしてみましたが同じです。
コンストラクターを使用して解決するこの投稿Honeycomb and TabHost specsを見つけましたが、xml をインフレートする必要があるため、このソリューションを使用できません。
誰かが私を助けてくれますか?
よろしく
私はこれを見つけました:
http://code.google.com/p/android/issues/detail?id=22605
-.-'