安卓:我应该如何删除活动标题栏



我想去掉活动标题栏,因为它很烦人。

我以前得到的所有帮助都没有奏效:(。这是原始帖子。安卓:如何删除活动标题栏?

这是代码和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" />

谢谢你的帮助。

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

public class MainActivity extends ActionBarActivity {

尝试

public class MainActivity extends Activity {

确保在Manifest文件中,您不想在其中包含操作栏的活动具有:

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

以编程方式使用getSupportActionBar().hide();。。这应该是您的第一行

首先不要使用ActionBarActivity,你不需要一个操作栏,只需要扩展活动

将此代码放在setcontentview:之前

    requestWindowFeature(Window.FEATURE_NO_TITLE);

将Theme.AppCompat.Light用于您的活动主题

您可以做两件事。1) 如果您希望整个应用程序没有操作/标题栏,如:,您可以在<application>标签下的Manifest文件中应用No-Title-Bar的主题

<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) 您可以将主题应用于不想显示标题/动作栏的特定活动,如:

<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>

最新更新