Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法隐藏标题栏_Java_Android_Titlebar - Fatal编程技术网

Java 无法隐藏标题栏

Java 无法隐藏标题栏,java,android,titlebar,Java,Android,Titlebar,我是Android开发新手,我想在我的应用程序中隐藏标题栏 我尝试了所有我可以隐藏的酒吧,但应用程序要么停止或没有任何改变 我在虚拟设备上运行了演示。这是一款5.4英寸FWVGA手机。 我还尝试添加了android:theme=“@android:style/theme.Holo.NoActionBar.Fullscreen” 或 android:theme=“@android:style/theme.NoTitleBar(.Fullscreen)” 但不幸的是,应用程序停止了。 请告诉我如何隐

我是Android开发新手,我想在我的应用程序中隐藏标题栏

我尝试了所有我可以隐藏的酒吧,但应用程序要么停止或没有任何改变

我在虚拟设备上运行了演示。这是一款5.4英寸FWVGA手机。
我还尝试添加了
android:theme=“@android:style/theme.Holo.NoActionBar.Fullscreen”

android:theme=“@android:style/theme.NoTitleBar(.Fullscreen)”
但不幸的是,应用程序停止了。

请告诉我如何隐藏标题栏。
这是我的java代码、布局文件、AndroidManifest.xml和styles.xml。

package com.activitytest2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;

public class FirstActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //1.   getActionBar().hide();
    //2.   requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.first_layout);
    Button button1 = (Button) findViewById(R.id.button_1);
    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(FirstActivity.this,"You clicked button 1",Toast.LENGTH_SHORT).show();
        }
    });
}

}

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/button_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="button 1"/>
</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.activitytest2">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".FirstActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>


styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
 </resources>
package com.activitytest2;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.view.Window;
导入android.widget.Button;
导入android.widget.Toast;
公共类FirstActivity扩展了AppCompatActivity{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//1.getActionBar().hide();
//2.请求WindowFeature(窗口功能\u编号\u标题);
setContentView(R.layout.first_layout);
Button button1=(按钮)findViewById(R.id.Button_1);
button1.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
Toast.makeText(FirstActivity.this,“您单击了按钮1”,Toast.LENGTH_SHORT.show();
}
});
}
}
layout.xml
AndroidManifest.xml
styles.xml
@颜色/原色
@颜色/原色暗
@颜色/颜色重音

在onCreate()中,将删除标题栏。

无需添加
getActionBar().hide();

就这样做,

“无标题”功能的标志,关闭页面顶部的标题 屏幕

对于测试用例,将其添加到样式部分

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
供参考 你可以试试

 super.onCreate(savedInstanceState);  

    requestWindowFeature(Window.FEATURE_NO_TITLE);  
    //code that displays the content in full screen mode  
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
                WindowManager.LayoutParams.FLAG_FULLSCREEN);  
试试看

 requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView
之前,例如

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.first_layout);

}

您是否正在为您需要的AppCompat主题使用AppCompat活动。 用这个 Theme.AppCompat.Light.NoActionBar

//添加样式文件

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

//添加menifest

 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.SlamBook.NoActionBar">
    <activity android:name=".FirstActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

将您的样式替换为以下内容:这也将隐藏您的操作栏

<!-- 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>
    <item name="android:windowNoTitle">true</item>
</style>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
真的

转到简单方法。只需替换
getActionBar().hide();
getSupportActionBar().hide();

我希望这个解决方案能帮助你

"@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();       
    setContentView(R.layout.first_layout);"

对于
AppCompat
,以下解决方案适合我:

styles.xml
中添加没有操作栏的新主题样式,并设置
parent=“theme.AppCompat.NoActionBar”

结果如下:


您是否正在使用AppCompat活动来实现您需要的AppCompat主题。使用此主题。AppCompat.Light.NoActionBarI已尝试了以上所有操作,但仍然没有任何更改。感谢您的帮助。@AngusMurphy您有其他解决方案吗?我已经接受了答案,尽管我不知道为什么。但非常感谢您的帮助。首先,请清除您的pro然后运行Build->cleanproject…它工作顺利…我试过了。不要更改应用程序主题中的任何内容。
 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.SlamBook.NoActionBar">
    <activity android:name=".FirstActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<!-- 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>
    <item name="android:windowNoTitle">true</item>
</style>
"@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();       
    setContentView(R.layout.first_layout);"
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/colorPrimary</item>

</style>
<activity
        android:name=".ActivityName"
        android:theme="@style/SplashTheme"> // apply splash them here 

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>