【问题标题】:How to remove title bar in android?如何删除android中的标题栏?
【发布时间】:2015-01-31 04:31:34
【问题描述】:

我想做一个不包含标题栏的android程序。由于某种原因,我无法删除标题栏。 我已经尝试过这种编码。

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

这个我也试过但是程序突然停止了..

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

我该如何解决这个问题?

【问题讨论】:

    标签: android xml android-actionbar titlebar


    【解决方案1】:

    在 Style.xml 窗口中 (App->src->main->res->values->styles.xml) 将<resources> 更改为如下所示:

    <resources>
    
        <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    
        </style>
    
    </resources>
    

    【讨论】:

      【解决方案2】:

      这不适用于 Android Studio。您需要编辑您的 AndroidManifest.xml 并将此行添加到要删除窗口标题的 Activity:

      <activity
          ...    
          android:theme="@style/Theme.AppCompat.NoActionBar"
          ...
          >
      

      如果您需要在所有活动中删除标题,我建议选择无标题的应用主题。

      【讨论】:

        【解决方案3】:

        尝试改变

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        进入

        this.supportrequestWindowFeature(Window.FEATURE_NO_TITLE);

        为我工作

        【讨论】:

          【解决方案4】:

          在 android 应用程序中删除标题栏的几种干净且简单的方法。我已经在 Android Studio 2.1.1 中测试过它们

          1. 如果 MainActivity 扩展了 MainActivity.java 中的 AppCompatActivity,

            一个。可以在AndroidManifest.xml的activity标签中添加两个属性,

            android:label="@string/app_name" android:theme="@android:style/Theme.AppCompat.NoActionBar"> ... 活动>

            b.或者您可以在 MainActivity.java 文件的 onCreate() 中添加一个方法,在 setContentView(R.layout.activity_main);之前添加一个方法;

            getSupportActionBar().hide();

          2. 如果 MainActivity 扩展了 MainActivity.java 中的 Activity,

            一个。可以在AndroidManifest.xml的activity标签中添加两个属性,

            android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> ... 活动>

            b.或者您可以在 MainActivity.java 文件的 onCreate() 中添加一个方法,在 super.onCreate() 和 setContentView(R.layout.activity_main) 之前;

            requestWindowFeature(Window.FEATURE_NO_TITLE);

          【讨论】:

            【解决方案5】:

            请注意,您应该先拨打this.requestWindowFeature(Window.FEATURE_NO_TITLE),然后再拨打this.setContentView(R.layout.layout_name)

            【讨论】:

            • 已经这样做了...但是我已经解决了..lol ...只需将style.xml中的主题更改为无操作栏顺便说一句谢谢..
            【解决方案6】:

            用于保留上次设置 Copy This Code (Android studio) res>Values>Styles.xml

            <resources xmlns:android="http://schemas.android.com/apk/res/android" >
            
            <!-- Base application theme. -->
            
            
            <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
                <!-- Customize your theme here. -->
                <item name="colorPrimary">@color/colorPrimary</item>
                <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
                <item name="colorAccent">@color/colorAccent</item>
            
            </style>
            

            如果您需要 DarTheme 或类似的东西,请将 Youre Keyword 放在 AppCompact 之后的样式标签和 Parent 中。

            最好的祝福

            【讨论】:

              【解决方案7】:

              我发现最好使用“空活动”并将以下配置放入您的 app\src\main\res\values\Styles.xml:

               &lt;style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&gt;

              这将为您提供一个没有标题栏和白色背景的应用。

              【讨论】:

                【解决方案8】:

                在你的 onCreate() 中试试这个

                this.requestWindowFeature(Window.FEATURE_NO_TITLE);
                
                this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,       WindowManager.LayoutParams.FLAG_FULLSCREEN);
                
                 this.setContentView(R.layout.layout_name); 
                

                【讨论】:

                  【解决方案9】:

                  Style.xml 文件中添加此代码样式。

                  <!-- Base application theme. -->
                  <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
                      <!-- Customize your theme here. -->
                  </style>
                  
                  <style name="AppTheme" parent="AppBaseTheme">
                      <!--  All customizations that are NOT specific to a particular API-level can go here.-->
                       <item name="android:windowNoTitle">true</item>
                       <item name="android:windowActionBar">false</item>
                       <item name="colorPrimary">@color/colorPrimary</item>
                       <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
                       <item name="colorAccent">@color/colorAccent</item>
                  </style>
                  

                  【讨论】:

                    【解决方案10】:

                    styles.xml 文件(App/src/main/res/values/styles.xml) 中,将 更改为如下所示:

                    如果您发现:

                    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
                    

                    改成

                    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
                    

                    【讨论】:

                      【解决方案11】:

                      在 AndroidManifest.xml 中

                      在应用中

                      调用此行 ==> android:theme="@style/Theme.AppCompat.Light.NoActionBar"&gt;

                      在这一行之前 ==> activity android:name=".MainActivity"

                      【讨论】:

                        猜你喜欢
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 2015-12-06
                        • 1970-01-01
                        • 2011-01-27
                        相关资源
                        最近更新 更多