80,349
社区成员
发帖
与我相关
我的任务
分享
package com.example.helloandroid;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.util.Log;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setBackgroundResource(R.drawable.background)
Button aboutbutton = (Button)findViewById(R.id.about_button);
Button exitbutton = (Button)findViewById(R.id.exit_button);
Button newbutton = (Button)findViewById(R.id.new_button);
aboutbutton.setOnClickListener( new OnClickListener(){
public void onClick(View v){
switch(v.getId()){
case R.id.about_button:
Intent i = new Intent(MainActivity.this,AboutActivity.class);
startActivity(i);
break;
}}});
exitbutton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
switch(v.getId()){
case R.id.exit_button:
finish();
break;
}}});
newbutton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
switch(v.getId()){
case R.id.new_button:
openNewGameDialog();
break;
}}
});
}
private void setBackgroundResource(int lunch) {
// TODO Auto-generated method stub
}
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main,menu);
return true;
}
private void openNewGameDialog(){
new AlertDialog.Builder(this)
.setTitle(R.string.new_game_title)
.setItems(R.array.difficulty,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface,int i){
}
})
.show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:startColor="#FFFFFF"
android:endColor="#808080"
android:angle="270"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:orientation="vertical" >