本文介绍了自定义标题栏上面TabHost不来在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置自定义栏上方Tabhost。但它不会来的。我不希望使用requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);原因是我想使用相同的code在我所有的屏幕。而在所有其他屏幕谈到完美,除了这个屏幕有tabhost。任何原因 ?

I am trying to set Custom Bar above Tabhost. But it won't come. I don't want to use "requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);" reason being i want to use same code in all my screens. And in all other screens it comes perfect except this screen which has tabhost. Any reason ?

code为TitleBar中:

Code for TitleBar :

<RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/windowtitle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="#0a2436"
                android:gravity="center_horizontal|center_vertical"
                android:paddingBottom="10dip"
                android:paddingTop="10dip"
                android:src="@drawable/logo">
            </ImageView>

            <ImageButton
                android:id="@+id/syncbutton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="3dip"
                android:background="@android:color/transparent"
                android:src="@drawable/sync" 
                android:gravity="center"
                android:text="Sync" />
        </RelativeLayout>

全部code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/formLayout"
    android:layout_width="fill_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/windowtitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="#0a2436"
            android:gravity="center_horizontal|center_vertical"
            android:paddingBottom="10dip"
            android:paddingTop="10dip"
            android:src="@drawable/logo">
        </ImageView>

        <ImageButton
            android:id="@+id/syncbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginTop="3dip"
            android:background="@android:color/transparent"
            android:src="@drawable/sync" 
            android:gravity="center"
            android:text="Sync" />
    </RelativeLayout>

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="0dp" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true" />

            <View
                android:id="@+id/separator"
                android:layout_width="fill_parent"
                android:layout_height="2dip"
                android:layout_below="@android:id/tabs" />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/btnSend"
                android:layout_below="@+id/separator"
                android:paddingBottom="45dip" >

                <!-- Scrollview for message data -->

                <ScrollView
                    android:id="@+id/formTab"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:scrollbars="vertical" >

                    <LinearLayout
                        android:id="@+id/formLayout"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical" >

                        <View
                            android:layout_width="fill_parent"
                            android:layout_height="5dip" />
                    </LinearLayout>
                </ScrollView>
            </FrameLayout>
        </RelativeLayout>
    </TabHost>

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:gravity="bottom"
        android:stretchColumns="*" >

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" >

            <Button
                android:id="@+id/home"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:background="#092435"
                android:gravity="center"
                android:padding="15dip"
                android:text="Activity"
                android:textColor="#ffffff" />

            <Button
                android:id="@+id/status"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:background="#092435"
                android:gravity="center"
                android:padding="15dip"
                android:text="Support"
                android:textColor="#ffffff" />

            <Button
                android:id="@+id/support"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:background="#092435"
                android:gravity="center"
                android:padding="15dip"
                android:text="Messages"
                android:textColor="#ffffff" />
        </TableRow>
    </TableLayout>

</RelativeLayout>

问候

推荐答案

更改您的布局这个......因为你需要的标题布局涉及您的tabhost

Change you layout to this...because you need to relate your tabhost with the title layout

添加的android:layout_below 属性的tabhost

add android:layout_below attribute to the tabhost


<RelativeLayout
    android:id="@+id/title"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/windowtitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="#0a2436"
        android:gravity="center_horizontal|center_vertical"
        android:paddingBottom="10dip"
        android:paddingTop="10dip"
        android:src="@drawable/ic_launcher" >
    </ImageView>

    <ImageButton
        android:id="@+id/syncbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginTop="3dip"
        android:background="@android:color/transparent"
        android:gravity="center"
        android:src="@drawable/ic_launcher"
        android:text="Sync" />
</RelativeLayout>

<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/title" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="0dp" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true" />

        <View
            android:id="@+id/separator"
            android:layout_width="fill_parent"
            android:layout_height="2dip"
            android:layout_below="@android:id/tabs" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/btnSend"
            android:layout_below="@+id/separator"
            android:paddingBottom="45dip" >

            <!-- Scrollview for message data -->

            <ScrollView
                android:id="@+id/formTab"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:scrollbars="vertical" >

                <LinearLayout
                    android:id="@+id/formLayout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                    <View
                        android:layout_width="fill_parent"
                        android:layout_height="5dip" />
                </LinearLayout>
            </ScrollView>
        </FrameLayout>
    </RelativeLayout>
</TabHost>

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:gravity="bottom"
    android:stretchColumns="*" >

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >

        <Button
            android:id="@+id/home"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:background="#092435"
            android:gravity="center"
            android:padding="15dip"
            android:text="Activity"
            android:textColor="#ffffff" />

        <Button
            android:id="@+id/status"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:background="#092435"
            android:gravity="center"
            android:padding="15dip"
            android:text="Support"
            android:textColor="#ffffff" />

        <Button
            android:id="@+id/support"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:background="#092435"
            android:gravity="center"
            android:padding="15dip"
            android:text="Messages"
            android:textColor="#ffffff" />
    </TableRow>
</TableLayout>

</RelativeLayout>

这篇关于自定义标题栏上面TabHost不来在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 00:25