http://hi.baidu.com/lynn185/item/87ff8c0a8f40d7066d90487d
近期刚刚接触到Android,由于原来是做Java的,再加上对嵌入式比较感兴趣的缘故,所以闲暇之余就搞搞Android的开发。
众所周知,手机的界面相对较小,因此有时对界面进行布局设计的时候,总感觉不能如我们所愿。因此我们常常会想办法把屏幕的可用之处尽量变大,而去掉标题栏或者隐藏状态栏就是我们唯一的也是最好的选择。
测试环境:Eclipse 3.4+ADT 0.9+Android SDK 1.6
在Android中去掉标题栏的方法如下2种:
Java代码:requestWindowFeature(Window.FEATURE_NO_TITLE);
XML配置文件:android:theme="@android:style/Theme.NoTitleBar"
根绝个人的习惯,你可以选择在代码中进行隐藏,也可以在xml文件中进行隐藏。
下面是去掉状态栏的方法:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
如上所说,如果我们在程序中把两种方法都是用的话,就可以把状态栏和标题栏同时隐藏掉,这样就会达到我们想全屏的目的。
一般的,我们全屏显示的原因就是想在屏幕上布局较多的界面元素,那么我们就来添加一些元素,首先我们来添加一个按钮,这时问题出现了,界面是全屏了,但是当我滑动鼠标或者点击导航键的时候,屏幕会整体下移一个相当于一个标题栏的高度。如下图红色部分即为下移后才显示出来的:
我就很纳闷,后来经过我跟踪发现,假如标题栏或者状态栏只要显示任何其中一个,就不会出现界面下移的这种情况。我就又继续跟踪测试发现全屏模式下,添加其他组件都没有任何界面下移的情况,就只有当我试图添加一个按钮的时候,才回出现这种情况,因此我认为这是Android的一个BUG。果然,我继续在其它版本的SDK下测试了一下,结果发现1.5和1.6都会出现这种全屏后界面整体下移的问题,在2.0,2.0.1和2.1平台下不会出现上述问题。看样子是官方及时的修正了这个问题,就是不知道,在已经安装了1.5和1.6的手机中是否有这种补丁可以下载更正。否则的话,1.5和1.6的用户看样子是很难体验全屏的感觉了。好在现在网络发达,网上有很多刷机的教程,不懂计算机的人员也可以通过自己刷机来解决这个问题。
那么在1.5和1.6平台真的就没有其他的方法可以正常的现实全屏了吗?
非也!我们还可以通过另一种方法来实现我们喜欢的全屏的模式,下面就来看一下这种方法。
隐藏状态栏代码:
getWindow().setFlags(WindowManager.LayoutParams.TYPE_STATUS_BAR,
WindowManager.LayoutParams.TYPE_STATUS_BAR);
细心的朋友可能发现了,这行代码和上面隐藏状态栏的行数是一样的,只是里面的参数换了而已。经测试,在这种情况下,的确可以正常的显示界面,但是另一个问题又出现了,说明一下此次的测试环境是SDK1.6。这样实现全屏的话,我发现添加的按钮不会响应onTouch()事件,不过还可以响应onClick()事件,我认为是又一个BUG。其它的组件会不会响应以及在其他的SDK下触摸事件是不是修正了,我没有测试,感兴趣的朋友可以自己测试一下。
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/LedwQ_MoNao
Hi guys,
I've found an irritating bug that I could please use some help with.
My application is styled to show no title (android:windowNoTitle) and
in onCreate() in the activity the system toolbar is hidden to display
as fullscreen. There are two buttons in the activity's relative
layout, aligned top of parent and bottom. The bug happens when I use 5-
way navigation to focus the top button. The screen momentarily shifts
or bounces down the size of the default titlebar. In some instances
part of the bottom content gets clipped. Here is a mini app I created
to reproduce the bug. Any help to workaround this bug would be
appreciated! Note: you may have to run the app twice to see this
behavior.
Brady
[bug.java]
package com.adobe.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;
public class StatusBarBug extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(
getWindow().
WindowManager.LayoutParams.
setContentView(R.layout.main);
}
}
[main.xml]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=" http://schemas.
android"
android:layout_width="
android:layout_height=
<Button
<Button android:layout_width="wrap_
<
</Button>
</RelativeLayout>
[styles.xml]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Themes -->
<style name="StatusBarTheme">
<item name="android:windowNoTitle">
</style>
</resources>
[manifest.xml]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=" http://schemas.
package="com.adobe.test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/
app_name"
android:theme="@style/
<activity android:name=".StatusBarBug"
android:label="@string/app_
<intent-filter>
<action android:name="android.intent.
<category
android:name="android.intent.
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
This looks like a total hack but by adding this line
getWindow().setFlags(
WindowManager.LayoutParams.
to the code I don't have the problem anymore.
This workaround kind of makes sense assuming something was being drawn
outside of the viewable bounds of the screen (like the titlebar, or
focus state of the button). The screen now won't shift to show
offscreen content because it can extend outside of the viewable screen
with this flag.
It still seems like a bug needs to be logged against this.
Brady
---------------------------------comment from forlong401--------------------------
可以考虑在每次屏幕切换或者view的显示、隐藏等操作时,再次调用一下:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
或者使用android:theme="@android:style/Theme.NoTitleBar.Fullscreen"代替
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
这个问题在android4.0以后就不存在了。只是在android2.3,android2.2等机器上出现。