Java 删除标题栏时出错

Java 删除标题栏时出错,java,android,eclipse,android-actionbar,android-titlebar,Java,Android,Eclipse,Android Actionbar,Android Titlebar,请看一下下面的代码 import android.os.Bundle; import android.app.ActionBar; import android.app.Activity; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.view.Menu; import android.view.View; import android.view.Wind

请看一下下面的代码

import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

public class Home extends Activity {

    private TextView textView23;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

         //Removing the title bar
         this.requestWindowFeature(Window.FEATURE_NO_TITLE);


         setContentView(R.layout.activity_home);

        //Setting up the Action Bar
         ActionBar actionBar = getActionBar();  //to support lower version too
         actionBar.setDisplayShowCustomEnabled(true);
         View customView=getLayoutInflater().inflate(R.layout.window_title, null);
         actionBar.setCustomView(customView);
         actionBar.setBackgroundDrawable(new ColorDrawable(Color.WHITE));



        textView23 = (TextView)findViewById(R.id.textView23);
        textView23.setSelected(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }

}
我正在删除应用程序的标题栏。但是,一旦执行了这段代码,我就会得到以下错误

10-30 08:09:58.480: E/AndroidRuntime(2747): FATAL EXCEPTION: main
10-30 08:09:58.480: E/AndroidRuntime(2747): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.xx/com.xx.xx.Home}: java.lang.NullPointerException
10-30 08:09:58.480: E/AndroidRuntime(2747):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at android.os.Looper.loop(Looper.java:137)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at android.app.ActivityThread.main(ActivityThread.java:5041)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at java.lang.reflect.Method.invokeNative(Native Method)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at java.lang.reflect.Method.invoke(Method.java:511)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at dalvik.system.NativeStart.main(Native Method)
10-30 08:09:58.480: E/AndroidRuntime(2747): Caused by: java.lang.NullPointerException
10-30 08:09:58.480: E/AndroidRuntime(2747):     at com.xx.xx.Home.onCreate(Home.java:29)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at android.app.Activity.performCreate(Activity.java:5104)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-30 08:09:58.480: E/AndroidRuntime(2747):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
10-30 08:09:58.480: E/AndroidRuntime(2747):     ... 11 more
我之所以尝试这样做是因为以下输出


如您所见,应用程序标题和我的操作栏都显示出来。我不想要应用程序标题或标题图像。

试试这个:
this.requestWindowFeature(getWindow().FEATURE\u NO\u title)
这对我有用

还可以尝试以下方法: 在AndroidManifest
标记中,添加:

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

没有标题就不能使用ActionBar。因此,请删除该行

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
您的主要目的是从标题栏中删除标题和图标,然后使用下面的代码

ActionBar actionBar = getActionBar();  //to support lower version too
actionBar.setDisplayShowHomeEnabled(false); // Remove icon
actionBar.setDisplayShowTitleEnabled(false); // Remove title text
actionBar.setDisplayShowCustomEnabled(true);
View customView=getLayoutInflater().inflate(R.layout.window_title, null);
actionBar.setCustomView(customView);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.WHITE));

在清单中,您可以使用主题
android:theme=“@android:style/theme.NoTitleBar.Fullscreen”
作为
标记

将此
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,
WindowManager.LayoutParams.FLAG(全屏)在java类中

这将删除默认的应用程序名称和图标

然后,您可以使用ActionBar设置应用程序名称