gpt4 book ai didi

java - Android:我应该如何删除 Activity 标题栏?

转载 作者:太空宇宙 更新时间:2023-11-04 14:10:41 25 4
gpt4 key购买 nike

我想摆脱 Activity 标题栏,因为它很烦人。

我之前收到的所有帮助都不起作用:(。这是原始帖子。 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" />

感谢您的所有帮助。

最佳答案

您的声明特别要求操作栏

public class MainActivity extends ActionBarActivity {

尝试

public class MainActivity extends Activity {

关于java - Android:我应该如何删除 Activity 标题栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28357484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com