Android : Full Screen Activity with Title bar

时光怂恿深爱的人放手 提交于 2019-12-19 03:08:42

问题


i want to set my Activity full Screen with Title bar , how can i do this ? thanks


回答1:


In 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>

Refer to your custom style in your mainfest:

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

To be truthful I've not tested this combination myself.




回答2:


This worked for me:

// Remove System bar (and retain title bar)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                     WindowManager.LayoutParams.FLAG_FULLSCREEN);

In code it would look like this:

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);
    }
}



回答3:


To create a full screen app with a custom title style, override some attributes of a full screen theme like so:

<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>

and modify as you wish.




回答4:


I suggest you to set fullscreen theme for activity e.g. Theme.Black.NoTitleBar.Fullscreen and create custom title bar in activity layout.




回答5:


Set your App theme as Theme.Holo.Compactmenu to make your title bar visible along with the icon



来源:https://stackoverflow.com/questions/12754897/android-full-screen-activity-with-title-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!