zoukankan      html  css  js  c++  java
  • android去掉标题方法

    在实际的应用程序开发中,我们有时需要把 Activity 设置成全屏显示,一般情况下,可以通过两种方式来设置全屏显示效果:

    其一:在代码onCreate里面setContentView之前设置(如下)
    view plaincopy to clipboardprint?
       public void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                         //取消标题
                          requestWindowFeature(Window.FEATURE_NO_TITLE);
                         //取消状态栏
                        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
                        setContentView(R.layout.main);
         }

    但要注意的是:在代码中设置的话,设置无标题和设置全屏的两段代码要放置在setContentView(R.layout.main)(界面渲染,完成了再全屏是不行的)这段代码的前面。要不然会报错 .

    其二:在manifest配置文件中设置

    第一种方法
    ①在res/values 目录创建个theme.xml文件(用来放样式)

       <?xml version="1.0" encoding="utf-8"?>
            <resources>
            <!-- name 是Style的名称,parent 继承那个父类样式 -->
                      <style name="theme_fullScreen" parent="android:Theme.Black">
                      <item name="android:windowNoTitle">true</item> <!-- 设置无标题 -->
                       <item name="android:windowFullscreen">?android:windowNoTitle</item>

                      <!-- 是否填充慢屏幕,引用android:windowNoTitle 的值 ?android:windowNoTitle,取决于android:windowNoTitle 的值-->
                    </style>
             </resources>

    ②<activity android:name=".login.LoginActivity" android:theme="@style/theme_fullScreen"/>

    第二种方法

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.andyidea"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".login.LoginActivity"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:label="@string/app_name">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    </application>
    </manifest>

    第三种:这种在一般的应用中不常用,就是在res/values目录下面新建一个style.xml的文件例如:
    <?xml version="1.0" encoding="UTF-8" ?>
    <resources>
          <style name="theme_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/theme_notitle">
    这样也可以达到去掉标题栏的效果

  • 相关阅读:
    【hihocoder】1237 : Farthest Point 微软2016校招在线笔试题
    POJ 1061青蛙的约会。求解(x+mT)%L=(y+nT)%L的最小步数T。
    Gym 100633G Nano alarm-clocks
    shell script 的追踪与 debug
    vim使用心得
    Linux修改vimrc配置文件,让vi更贴心
    shell script中的case……esac判断
    stl容器区别: vector list deque set map-底层实现
    const对象为什么可以在头文件中定义
    shell script中的syntax error near unexpected token `then' 问题
  • 原文地址:https://www.cnblogs.com/javadan/p/4788099.html
Copyright © 2011-2022 走看看