简体   繁体   English

Android:如何删除活动标题栏?

[英]Android: How should I remove the Activity Title Bar?

I am wanting to get rid of the Activity Title Bar as it is annoying to have. 我想摆脱活动标题栏,因为它很烦人。

All of the previous help I have received has not worked :(. Here is the original post. Android: How to remove the Activity Title Bar? 我以前收到的所有帮助均无效:( ..这是原始帖子。Android:如何删除“活动标题栏”?

Here is the code and xml file. 这是代码和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" />

Thanks for any and all help. 感谢您提供的所有帮助。

Your declaration specifically asks for an action bar 您的声明明确要求采取行动

public class MainActivity extends ActionBarActivity {

try 尝试

public class MainActivity extends Activity {

Make sure in your Manifest file, the activity you don't want to have the actionbar in has: 确保在清单文件中,您不想包含动作栏的活动具有:

android:theme="@android:style/Theme.NoTitleBar" 机器人:主题= “@安卓风格/ Theme.NoTitleBar”

use getSupportActionBar().hide(); 使用getSupportActionBar().hide(); programmatically..this should be your first line 以编程方式..这应该是您的第一行

First of all don't use ActionBarActivity ,You don't need an action bar just extend Activity 首先,不要使用ActionBarActivity,您不需要操作栏,只需扩展Activity

Put this code before setcontentview : 将此代码放在setcontentview之前:

    requestWindowFeature(Window.FEATURE_NO_TITLE);

Use Theme.AppCompat.Light for your activity theme 使用Theme.AppCompat.Light作为您的活动主题

There are two things you can do. 您可以做两件事。 1) You can apply theme of No-Title-Bar in your Manifest file under <application> tag if you want the whole application without action/title bar like: 1)如果您希望整个应用程序没有动作/标题栏,则可以在<application>标记下的清单文件中<application> 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) You can apply theme to particular activity in which you don't want to show title/action bar like: 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM