2015-02-06 73 views
1

我想摆脱活动标题栏,因为它是烦人的。Android:我应该如何删除活动标题栏?

前面的所有帮助我收到没有奏效:(这里是原来的职位。 Android: How to remove the Activity Title Bar?

这里是代码和XML文件。

package com.example.ryanfolz.gridgame; 

import android.content.Context; 
import android.content.Intent; 
import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.Window; 
import android.widget.Button; 


public class MainActivity extends ActionBarActivity { 

private Context ctx; 




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

    setContentView(R.layout.activity_main); 

    ctx = this; 
    Button startButton = (Button) findViewById(R.id.start_button); 
    startButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent gotoChooseGame = new Intent(ctx, WhichGameActivity.class); 
      finish(); 
      startActivity(gotoChooseGame); 

     } 
    }); 
    Button optionsButton = (Button)findViewById(R.id.options_button); 
    optionsButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent gotoChooseGame = new Intent(ctx, WhichGameActivity.class); 
      finish(); 
      startActivity(gotoChooseGame); 

     } 
    }); 






} 


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

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 


} 


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="center" 
android:theme="@android:style/Theme.NoTitleBar" 
android:background="#ff000000"> 

<Button 
    android:layout_width="120dp" 
    android:layout_height="65dp" 
    android:id="@+id/start_button" 
    android:padding="15dp" 
    android:text="@string/play" 
    android:textSize="18sp" 
    android:background="#fffff6f9"/> 

<Button 
    android:layout_width="120dp" 
    android:layout_height="65dp" 
    android:text="@string/options" 
    android:id="@+id/options_button" 
    android:padding="15dp" 
    android:layout_below="@+id/start_button" 
    android:layout_alignLeft="@+id/start_button" 
    android:layout_alignStart="@+id/start_button" 
    android:background="#fffff6f9" 
    android:layout_marginTop="44dp" /> 

谢谢对于任何和所有的帮助。

+0

您的清单文件对于该活动的外观如何? – Mikerizzo 2015-02-06 02:21:21

+1

不需要操作栏,使用为旧API级别添加操作栏的兼容性类。 – tachyonflux 2015-02-06 02:22:26

回答

0

你的声明特别要求一个操作栏

public class MainActivity extends ActionBarActivity { 

尝试

public class MainActivity extends Activity { 
+0

不。这表示它是一个appcompat活动。 – Shmuel 2015-02-06 03:09:08

0

清单档案中的确保,活动你不希望有动作条中有:

机器人:主题=“@安卓风格/主题.NoTitleBar”

+0

我得到错误“您需要使用Theme.AppCompat主题(或后代)进行此活动。”每当我试图做到这一点。 – Kinoscorpia 2015-02-06 03:40:01

+0

那么你需要使用应用程序正在使用的主题。请编辑您的问题并发布您的清单文件。 – Mikerizzo 2015-02-06 18:50:07

0

使用getSupportActionBar().hide(); programmatically..this应该是你的第一行

+0

我得到错误java.lang.NullPointerException – Kinoscorpia 2015-02-06 03:41:13

+0

你能告诉我错误@ Kinoscorpia – Elltz 2015-02-06 10:26:12

0

首先,不使用法ionBarActivity,你并不需要一个操作栏只是延长活动

将这个代码的setContentView前:

requestWindowFeature(Window.FEATURE_NO_TITLE); 

使用Theme.AppCompat.Light您的活动主题

0

有两两件事你可以做。 1)您可以在清单文件适用的No-Title-Bar主题下<application>标签,如果你想不整个应用程序动作/标题栏,如:

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

     // your all activities..... 

</application> 

2)您可以应用主题,在你不特定活动t想要显示标题/动作栏,如:

<application 
      android:allowBackup="true" 
      android:icon="@drawable/app_icon" 
      android:label="@string/app_name" 
      android:theme="@style/AppTheme"> 

      <activity name="com.yourpackage.activity_name" 
        android:theme="@android:style/Theme.Light.NoTitleBar"> 
      </activity> 

    </application>