zoukankan      html  css  js  c++  java
  • 【Android 界面效果13】关于全屏和取消标题栏

    ------- 源自梦想永远是你IT事业的好友、只是勇敢地说出我学到! ----------


    去掉标题栏:

    第一种:也一般入门的时候经常使用的一种方法

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

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

    第二种:在AndroidManifest.xml文件中定义

    <application android:icon="@drawable/icon" 
            android:label="@string/app_name" 
            android:theme="@android:style/Theme.NoTitleBar">


    可以看出,这样写的话,整个应用都会去掉标题栏,如果只想去掉某一个Activity的标题栏的话,可以把这个属性加到activity标签里面

    第三种:这种在一般的应用中不常用,就是在res/values目录下面新建一个style.xml的文件

    例如:

    <?xml version="1.0" encoding="UTF-8" ?>
    <resources>
        <style name="notitle">
            <item name="android:windowNoTitle">true</item>
        </style> 
    </resources>


    这样,我们就自定义了一个style,就相当于一个主题,然后在AndroidManifest.xml文件中定义

    <application android:icon="@drawable/icon"
             android:label="@string/app_name"
             android:theme="@style/notitle">



    这样也可以达到去掉标题栏的效果

    三种去掉标题栏方法的总结

    第一种,有的时候我们会看到,会先出现标题栏,然后再消失,因为我们只是在activityoncreate方法中定义的,第二种相对第一种比较好一些,不会出现这种情况,第三种我个人感觉最好,这样把功能分开,便于维护和扩展




    全屏:

    第一种

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


    第二种

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


    第三种

    application android:icon="@drawable/icon" 
            android:label="@string/app_name"
            android:theme="@style/fullscreem"

    全屏效果:




    还有其他的一些对标题栏的设置:

    1、隐藏标题栏
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    2、在标题栏显示进度条
    requestWindowFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.progressbar_1);
    setProgressBarVisibility(true);

    final ProgressBar progressHorizontal = (ProgressBar) findViewById(R.id.progress_horizontal);
    setProgress(progressHorizontal.getProgress() * 100);
    setSecondaryProgress(progressHorizontal.getSecondaryProgress() * 100);

    3、使用自定义标题栏
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.xxx);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.my_title_bar);

    4、清除标题栏内容,而区域保留
    ((ViewGroup) getWindow().findViewById(com.android.internal.R.id.title_container)).removeAllViews();

    5、隐藏标题栏
    ((ViewGroup)getWindow().
      findViewById(com.android.internal.R.id.title_container)).setVisibility(View.GONE);

    6、显示标题栏
    ...setVisibility(View.VISIBLE);

    其他注意事项
    (1) requestWindowFeature()要在setContentView()之前调用;
    (2) 设置各种Feature,是具有排它性的,一旦设置,后续不可更改为别的类型;

    (3) 当使用TabHost(由ActivityGroup派生)时,各个Tab里的Activity,要么都是NO_TITLE,要么都是CUSTOM_TITLE,无法分别进行设置。



    ------- 源自梦想永远是你IT事业的好友、只是勇敢地说出我学到! ----------
    Le王冬冬 博客分享地址: http://www.cnblogs.com/dongdong230/ 每个人都应做一天攻城狮
  • 相关阅读:
    27. Remove Element
    26. Remove Duplicates from Sorted Array
    643. Maximum Average Subarray I
    674. Longest Continuous Increasing Subsequence
    1. Two Sum
    217. Contains Duplicate
    448. Find All Numbers Disappeared in an Array
    566. Reshape the Matrix
    628. Maximum Product of Three Numbers
    UVa 1349 Optimal Bus Route Design (最佳完美匹配)
  • 原文地址:https://www.cnblogs.com/dongdong230/p/4183111.html
Copyright © 2011-2022 走看看