Android:带有标题栏的全屏活动

Android:带有标题栏的全屏活动,android,android-activity,themes,Android,Android Activity,Themes,我想用标题栏设置我的活动全屏,我该怎么做?谢谢我建议您为活动设置全屏主题,例如theme.Black.NoTitleBar.fullscreen,并在活动布局中创建自定义标题栏。在styles.xml中: <resources> <style name="Theme.FullScreen" parent="@android:style/Theme.Holo"> <item name="android:windowNoTitle">false<

我想用标题栏设置我的活动全屏,我该怎么做?谢谢

我建议您为活动设置全屏主题,例如theme.Black.NoTitleBar.fullscreen,并在活动布局中创建自定义标题栏。

在styles.xml中:

<resources>
   <style name="Theme.FullScreen" parent="@android:style/Theme.Holo">
   <item name="android:windowNoTitle">false</item>
   <item name="android:windowFullscreen">true</item>
   </style>
</resources>

假的
真的
请参阅mainfest中的自定义样式:

<activity android:name=".MyActivity" android:theme="@style/Theme.FullScreen"/>


老实说,我自己没有测试过这种组合。

要创建具有自定义标题样式的全屏应用程序,请覆盖全屏主题的某些属性,如下所示:

<style name="AppTheme" parent="@android:style/Theme.Light.NoTitleBar.Fullscreen">
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowTitleSize">45dip</item>
    <item name="android:windowTitleBackgroundStyle">@style/TitleBackgroundStyle</item>
</style>

<style name="TitleBackgroundStyle">
    <item name="android:background">@drawable/title</item>
</style>

假的
45度
@样式/标题背景样式
@可提取/标题
并根据您的意愿进行修改。

这对我很有用:

// Remove System bar (and retain title bar)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
在代码中,它将如下所示:

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class ActivityName extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Remove System bar (and retain title bar)
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // Set your layout
        setContentView(R.layout.main);
    }
}

将你的应用程序主题设置为theme.Holo.Compactmenu,使你的标题栏和图标一起可见

,效果很好,完全符合我的需要。如果您没有styles.xml文件,您可以在values下创建一个文件,并将其放入其中。文件名并不重要,因为系统通过样式名访问它。