我想摆脱活动标题栏,因为它是烦人的。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" />
谢谢对于任何和所有的帮助。
您的清单文件对于该活动的外观如何? – Mikerizzo 2015-02-06 02:21:21
不需要操作栏,使用为旧API级别添加操作栏的兼容性类。 – tachyonflux 2015-02-06 02:22:26