Android 标题栏在应用程序恢复时留下空间

发布于 2024-12-22 13:57:32 字数 3879 浏览 2 评论 0原文

我在 Android 应用程序中使用 Tab Host。我隐藏了标题栏。

当我离开应用程序并恢复它时,我有一些奇怪的行为。

如果我使用 listView.setAdapter 的列表活动恢复到选项卡,则标题栏将被隐藏,并且它占用的空间将被应用程序消耗。但是,如果我恢复到任何没有 listView.setAdapter 的选项卡,标题栏将被隐藏,但它使用的空间会被留下。

这会将我的选项卡(位于屏幕底部)推离屏幕。如果我随后更改为任何其他选项卡,该空间将再次被我的应用程序消耗。

我试图使我的应用程序中的大多数明显视图无效,但没有成功。下面是我的 tab_activity xml。非常感谢

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <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="0dip"
                    android:layout_weight="1" />

                <TabWidget android:id="@android:id/tabs"
                    android:layout_width="fill_parent" android:layout_height="wrap_content"
                    android:layout_weight="0" />
            </LinearLayout>
        </TabHost>

    </LinearLayout>

这是清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tar.projectx" android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />

    <application android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <activity android:name=".Splash" android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" android:label="@string/app_name" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="SearchActivity" android:label="SearchActivity" android:screenOrientation="portrait"></activity>
        <activity android:name="SearchListActivity" android:label="SearchListActivity" android:screenOrientation="portrait"></activity>
        <activity android:name="ContactActivity" android:label="ContactActivity" android:screenOrientation="portrait"></activity>
    </application>
</manifest>

有趣的是,如果我在保存 tabhost 的 mainActivity 的 onResume 方法中使用下面的代码,一旦 toast 消失,视图就会刷新,并且顶部的空间再次被我的应用程序占用。显然,这并不是一个解决办法,但可以帮助人们了解正在发生的事情。

@Override
    protected void onResume() {
        super.onResume();

        Toast.makeText(this, "Welcome Back", Toast.LENGTH_LONG).show();
    } 

I am using a Tab Host in my Android App. I have the Titlebar hidden.

When I leave the App and resume to it, I have some strange behaviour.

If I resume to a tab using a list activity with listView.setAdapter, the title bar is hidden and the space it takes up is consumed by the App. However, if I resume to any tab without the listView.setAdapter, the Titlebar is hidden, but space which was used by it is left behind.

This is pushes my tabs (which are positioned at the bottom of the screen) off the screen. The space is once again consumed by my app if I then change to any other tab.

I have tried to invalidate most of the obvious Views in my App without and success. Below is my tab_activity xml. many thanks

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <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="0dip"
                    android:layout_weight="1" />

                <TabWidget android:id="@android:id/tabs"
                    android:layout_width="fill_parent" android:layout_height="wrap_content"
                    android:layout_weight="0" />
            </LinearLayout>
        </TabHost>

    </LinearLayout>

Here is the Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tar.projectx" android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />

    <application android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <activity android:name=".Splash" android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" android:label="@string/app_name" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="SearchActivity" android:label="SearchActivity" android:screenOrientation="portrait"></activity>
        <activity android:name="SearchListActivity" android:label="SearchListActivity" android:screenOrientation="portrait"></activity>
        <activity android:name="ContactActivity" android:label="ContactActivity" android:screenOrientation="portrait"></activity>
    </application>
</manifest>

Interestingly, if I use the code below in the onResume method of my mainActivity which holds the tabhost, once the toast disappears, the view is refreshed and the space at the top is taken up by my app again. Obviously, this isn't much of a fix, but may help someone understand what is happening.

@Override
    protected void onResume() {
        super.onResume();

        Toast.makeText(this, "Welcome Back", Toast.LENGTH_LONG).show();
    } 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨与橙与城 2024-12-29 13:57:32

我会尝试在我的 onResume() 中手动调用 requestLayout() 和/或 requestWindowFeature(Window.FEATURE_NO_TITLE) ...此外,尝试查看何时为您的视图调用 onMeasure() 方法。这只是我的想法;)希望它有帮助。干杯!

I would try to manually call requestLayout() and/or requestWindowFeature(Window.FEATURE_NO_TITLE) in my onResume()... furthermore, try seeing when is the onMeasure() method called for your view. This is just out of the top of my head ;) hope it helps. Cheers!

最近可好 2024-12-29 13:57:32

请将主选项卡栏活动主题设置为 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

Pleas set main Tab bar activity theme as android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文