0

我的应用程序具有表单,用户可以在其中添加有关其企业的信息。我将 TabHost 组件用于四个类别。在 XML 中,我的应用程序中有四种表单的布局(xml 代码如下)。My Activity with tabs 适用于各种带有 Android Gingerbread 的设备,但不适用于带有 Android Ice Cream Sandwich 的设备。例如,当我想在 Android 2.3.3 上的 tabAddress 中选择 EditText 编号 4 时,我可以选择这些字段,然后我可以在其中写一些东西。当我想在 Android 4.1.2 或 4.2 上做同样的事情时,我不能选择那个字段,因为这个机制在这个版本的 Android 中不起作用。在最后一个选项卡中,我可以选择 Gingerbread 和 ICS 上的所有 EditText。我认为它就像 ICS 中的图层一样工作,我的最后一个选项卡(菜单)覆盖了其他选项卡。下面是我的 xml 代码和 Java 代码片段。我该如何解决这个问题?我希望它在 ICS 中的工作就像在 Andorid 4.3.3 上工作一样。

XML 代码:`

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:tabStripEnabled="false" />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

                <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <LinearLayout
                        android:id="@+id/tabAddress"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:orientation="vertical"
                        android:padding="10dp" >

                        ... other components (e.g. EditText)

                        <EditText
                            android:id="@+id/etName"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="10dp"
                            android:ems="10" />

                        ... other components (e.g. EditText)

                    </LinearLayout>
                </ScrollView>

                <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <LinearLayout
                        android:id="@+id/tabDetails"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:orientation="vertical"
                        android:padding="10dp" >

                        ... other components (e.g. EditText)

                        <EditText
                            android:id="@+id/etPhone"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="10dp"
                            android:ems="10" />

                        ... other components (e.g. EditText)

                    </LinearLayout>
                </ScrollView>

                <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <LinearLayout
                        android:id="@+id/tabHours"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:orientation="vertical"
                        android:padding="10dp" >

                        ... other components (e.g. EditText)

                        <EditText
                            android:id="@+id/etMonday"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="10dp"
                            android:ems="10" />

                        ... other components (e.g. EditText)

                    </LinearLayout>
                </ScrollView>

                <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <LinearLayout
                        android:id="@+id/tabMenu"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:orientation="vertical"
                        android:padding="10dp" >

                        ... other components (e.g. EditText)

                        <EditText
                            android:id="@+id/etProduct"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="10dp"
                            android:ems="10" />

                        ... other components (e.g. EditText)

                    </LinearLayout>
                </ScrollView>
            </FrameLayout>
        </LinearLayout>
    </TabHost>`

Java代码:

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    ...

    tabHost = (TabHost) findViewById(R.id.tabhost);
    tabHost.setup();

    addTab("Adres", R.id.tabAddress, R.drawable.home);
    addTab("Szczegóły", R.id.tabDetails, R.drawable.details);
    addTab("Godz.", R.id.tabHours, R.drawable.clock);
    addTab("Menu", R.id.tabMenu, R.drawable.menu);

    setTabColor(tabHost);

    ...
    }

public void addTab(String tabSpecTag, int viewId, int drawableId){
    tabSpecs = tabHost.newTabSpec(tabSpecTag);
    tabSpecs.setIndicator(tabSpecTag, getResources().getDrawable(drawableId));
    tabSpecs.setContent(viewId);
    tabHost.addTab(tabSpecs);
}
4

0 回答 0