Android界面去掉标题栏,设置为全屏显示

 Android界面去掉标题栏,设置为全屏显示
分类: Android基础篇 2013-03-22 16:50 881人阅读 评论(0) 收藏 举报
ANDROID去掉标题全屏显示
在应用的欢迎和导引界面,需要全屏显示;在其他界面去掉标题栏。
实现去掉标题栏,设置为全屏显示有两种方式:
1、硬编码实现:
 
requestWindowFeature(Window.FEATURE_NO_TITLE);  
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  

2、在AndroidManifest.xml中添加配置:
 
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"   
 android:theme="@android:style/Theme.NoTitleBar"  

我老是记不住,每次都从以前的项目代码里Copy,现在记在这里,以备后用。



状态栏高度算法:

状态栏高度算法:
/**
		 * 状态栏高度算法
		 * @param activity
		 * @return
		 */
		public static int getStatusHeight(Activity activity){  
		    int statusHeight = 0;  
		    Rect localRect = new Rect();  
		    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);  
		    statusHeight = localRect.top;  
		    if (0 == statusHeight){  
		        Class<?> localClass;  
		        try {  
		            localClass = Class.forName("com.android.internal.R$dimen");  
		            Object localObject = localClass.newInstance();  
		            int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString());  
		            statusHeight = activity.getResources().getDimensionPixelSize(i5);  
		        } catch (ClassNotFoundException e) {  
		            e.printStackTrace();  
		        } catch (IllegalAccessException e) {  
		            e.printStackTrace();  
		        } catch (InstantiationException e) {  
		            e.printStackTrace();  
		        } catch (NumberFormatException e) {  
		            e.printStackTrace();  
		        } catch (IllegalArgumentException e) {  
		            e.printStackTrace();  
		        } catch (SecurityException e) {  
		            e.printStackTrace();  
		        } catch (NoSuchFieldException e) {  
		            e.printStackTrace();  
		        }  
		    }  
		    return statusHeight;  
		}  







你可能感兴趣的:(设置为全屏显示)