一:标题栏

1继承Activity有效

1.1requestWindowFeature(Window.FEATURE_NO_TITLE);

注意这句一定要写在setContentView()方法的前面,不然会报错的

1.2在manifest.xml中改Theme

android:theme= "@android:style/Theme.NoTitleBar"

2继承AppCompatActivity有效

2.1代码中getSupportActionBar().hide();

2.2在manifest.xml中改Theme

 android:theme="@style/Theme.AppCompat.Light.NoActionBar"

会先出现标题栏,然后再消失,因为是在activity的oncreate方法中定义的,第二种相对第一种比较好一些,不会出现这种情况。

二;取消状态栏,和标题栏

继承Activity有效

requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

第二种
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

继承AppCompatActivity有效:

<style name= "MyFullScreenTheme" parent= "Theme.AppCompat.Light.NoActionBar" > <item name= "android:windowNoTitle" > true </item> <item name= "android:windowFullscreen" > true </item> <item name= "android:windowActionBar" > false </item> </style>

然后对应的activity设为这个主题

实现全屏:Android4.4以上包括4.4,

 @Override    public void onWindowFocusChanged(boolean hasFocus) {        // TODO Auto-generated method stub        super.onWindowFocusChanged(hasFocus);        if(hasFocus)        {            View decorView = getWindow().getDecorView();            decorView.setSystemUiVisibility(                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE//保持布局状态                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION//可以显示在导航栏后面                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//隐藏导航栏                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN//可以显示在状态栏后面                            | View.SYSTEM_UI_FLAG_FULLSCREEN//隐藏状态栏                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);//显示状态栏后几秒后消失        }    }

也可放在oncreate里面 setContentView之前

SYSTEM_UI_FLAG_IMMERSIVE 和SYSTEM_UI_FLAG_IMMERSIVE_STICKY两种区别:

前者是将 bar 唤出后不再消失,后者是将 bar 唤出后几秒就消失,后者不触发 Listener。

获取状态栏和导航栏高度

方法/**        //透明状态栏        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);        //透明导航栏        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);     * 获取状态栏高度     * @param context     * @return     */    public static int getStatusBarHeight(Context context) {        int result = 0;        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen",                "android");        if (resourceId > 0) {            result = context.getResources().getDimensionPixelSize(resourceId);        }        return result;    }    /**     * 获取导航栏高度     * @param context     * @return     */    public static int getDaoHangHeight(Context context) {        int result = 0;        int resourceId=0;        int rid = context.getResources().getIdentifier("config_showNavigationBar", "bool", "android");        if (rid!=0){             resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");            CMLog.show("高度:"+resourceId);            CMLog.show("高度:"+context.getResources().getDimensionPixelSize(resourceId) +"");            return context.getResources().getDimensionPixelSize(resourceId);        }else      

系统工具栏显示变化的响应

  注册一个 View.OnSystemUiVisibilityChangeListener 来使界面同步变化,可以在 onCreate() 方法中添加以下代码:

View decorView = getWindow().getDecorView();decorView.setOnSystemUiVisibilityChangeListener        (new View.OnSystemUiVisibilityChangeListener() {    @Override    public void onSystemUiVisibilityChange(int visibility) {        // Note that system bars will only be "visible" if none of the        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {            // TODO: The system bars are visible. Make any desired            // adjustments to your UI, such as showing the action bar or            // other navigational controls.        } else {            // TODO: The system bars are NOT visible. Make any desired            // adjustments to your UI, such as hiding the action bar or            // other navigational controls.        }    }});


更多相关文章

  1. Android基于基于布局嵌套的页面导航实现
  2. Android中设置屏幕全屏两种方法:
  3. android studio Could not find com.android.support.constraint
  4. android ndk编译x264开源(用于android的ffmpeg中进行软编码)
  5. Android软键盘适配问题
  6. GitHub 优秀的 Android(安卓)开源项目
  7. Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明
  8. Android(安卓)EditText 设置行距不影响光标高度
  9. android加密解密完美教程

随机推荐

  1. android studio编译android M时无法使用o
  2. Android设置透明效果
  3. 安卓XML布局,相对布局的常用属性~
  4. 关于GridView控件中设置大小的问题
  5. android 之 install Location
  6. Android(安卓)Studio启动安卓虚拟机失败,
  7. android屏幕页面实现滚动,页面跳…
  8. android 自带的主题 theme 的使用
  9. android:installLocation简析
  10. 自定义RadioButton 文字在下,图片在上