实现全屏无标题栏:

1.在xml文件中进行配置

AndroidManifest.xml中,找到需要全屏或设置成无标题栏的Activity,在该Activity进行如下配置即可。

全屏效果:android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  无标题栏(但有系统状态栏):android:theme="@android:style/Theme.NoTitleBar"  

2.编写代码设置
在程序中编写代码进行设置,只需在onCreate()方法中 setContentView方法之前加入如下代码:

// Full ScreengetWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);// No Titlebarthis.requestWindowFeature(Window.FEATURE_NO_TITLE);

可能出现的问题

Caused by: java.lang.IllegalStateException: You need to use a
Theme.AppCompat theme (or descendant) with this activity.

起因:在Manifest中设置activity全屏,代码如下:

".SplashActivity"      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"      android:label="@string/app_name" >  

原因: 从错误提示中提到Theme.AppCompat theme,这是因为我们的activity一定是继承了兼容包中的类,
比如我这里就无意中继承了AppCompatActivity,它来自android.support.v7.app.AppCompatActivity。
所以就要使用与其配合的AppCompat的theme才行。

解决:
方法1.根据提示来使用AppCompat的theme,如下:

".MainActivity"      android:theme="@style/Theme.AppCompat.Light.NoActionBar"      android:label="@string/app_name" >  

在onCreate方法中

@Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        // 全屏状态(消除状态栏)+androidManifest.xml:android:theme="@style/AppTheme.NoActionBar"        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);        setContentView(R.layout.activity_splash);        handler = new Handler();        handler.postDelayed(runnable, SPLASH_DISPLAY_LENGHT);    }

方法2.如果不是那么强烈需要继承自AppCompatActivity,就直接继承Activity

附:Android系统自带样式

android:theme=”@android:style/Theme.Dialog” 将一个Activity显示为对话框模式
android:theme=”@android:style/Theme.NoTitleBar” 不显示应用程序标题栏
android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”
不显示应用程序标题栏,并全屏 android:theme=”Theme.Light” 背景为白色
android:theme=”Theme.Light.NoTitleBar” 白色背景并无标题栏
android:theme=”Theme.Light.NoTitleBar.Fullscreen” 白色背景,无标题栏,全屏
android:theme=”Theme.Black” 背景黑色
android:theme=”Theme.Black.NoTitleBar” 黑色背景并无标题栏
android:theme=”Theme.Black.NoTitleBar.Fullscreen” 黑色背景,无标题栏,全屏
android:theme=”Theme.Wallpaper” 用系统桌面为应用程序背景
android:theme=”Theme.Wallpaper.NoTitleBar” 用系统桌面为应用程序背景,且无标题栏
android:theme=”Theme.Wallpaper.NoTitleBar.Fullscreen”
用系统桌面为应用程序背景,无标题栏,全屏 android:theme=”Translucent” 透明背景
android:theme=”Theme.Translucent.NoTitleBar” 透明背景并无标题
android:theme=”Theme.Translucent.NoTitleBar.Fullscreen” 透明背景并无标题,全屏
android:theme=”Theme.Panel” 面板风格显示 android:theme=”Theme.Light.Panel”
平板风格显示

更多相关文章

  1. Android应用程序结构
  2. Android 中三种使用线程的方法
  3. Android应用程序的Activity启动过程简要介绍和学习计划
  4. Android 圆形背景shape定义
  5. Android应用程序资源
  6. TableRow 背景问题以及修改对话框标题高度或者图片
  7. Android重启应用程序 && 不重启应用不改变系统语言改变 Android
  8. Android Activity onConfigurationChanged()方法 监听状态改变
  9. Android 背景色平铺。

随机推荐

  1. 阿里架构师最新整理 Android(安卓)面试点
  2. android 在APP内打开在线的office文件
  3. Android——View绘制流程
  4. Android(安卓)PopWindow与GridView练习
  5. Android——布局中bottom不起作用/left、
  6. Android之Android(安卓)studio设置背景图
  7. android gradle导入依赖的另一个方法
  8. NoClassDefFoundError: android/os/Persi
  9. Android(安卓)音视频开发(二) -- Camera1
  10. Android(安卓)Event事件传递机制总结