当前位置: 代码迷 >> Android >> 各位路过的神仙佛祖们,悟空有一有关问题实在不解,恳求神仙们赐教一二。想用这个setBackgroundResource引用背景的XML文件,无效果啊
  详细解决方案

各位路过的神仙佛祖们,悟空有一有关问题实在不解,恳求神仙们赐教一二。想用这个setBackgroundResource引用背景的XML文件,无效果啊

热度:30   发布时间:2016-05-01 11:20:27.0
各位路过的神仙佛祖们,悟空有一问题实在不解,恳求神仙们赐教一二。想用这个setBackgroundResource引用背景的XML文件,无效果啊。
本帖最后由 love_love_yyou 于 2012-12-10 12:51:45 编辑
我在工程的java文件的OnCreate()方法中调用setBackgroundResource(R.drawable.background),没什么用,还报错,后来根据提示加了个private void setBackgroundResource(int lunch) {
// TODO Auto-generated method stub
}貌似添加的方法里面要写局什么东西,不明所以啊。。。。
嘿嘿,大神们别笑,菜鸟,真的是菜鸟。
这是我的程序

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

<?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>
  相关解决方案