本帖最后由 henha2jiang 于 2013-06-19 19:05:10 编辑

解决方案 »

  1.   

     LayoutInflater regist_Inflater = LayoutInflater.from(Fx.this);                                     View fxView = regist_Inflater.inflate(R.layout.activity_fx, null);                                     fxView.findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK);//其中R.id.btn
    这个view没看到你用啊.
      

  2.   

     是fxView吗,这个view在fxView.findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK);这一句不是用了吗,完整点的代码是这样的
    public class Fx extends Activity {
    //声明Button对象
    Button button_regist;
    Button button_login;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_fx);        
            /*--------------按钮regist----------------*/
            button_regist = (Button)findViewById(R.id.btn_regist);
            button_regist.setOnClickListener(new btn_registOnclick());      
    }

    /*-------------------------regist监听器--------------------------------*/
    class btn_registOnclick implements OnClickListener{
    ProgressDialog r_Dialog;
    LayoutInflater regist_Inflater = LayoutInflater.from(Fx.this);
    final View registView = regist_Inflater.inflate(R.layout.regist, null);
    AlertDialog registDlg = new AlertDialog.Builder(Fx.this).
                    setTitle("请注册"). 
                    setView(registView).
                    setPositiveButton("确定",  new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton1) {
    // TODO Auto-generated method stub
    r_Dialog = ProgressDialog.show(Fx.this, "请等待...", "正在为您注册...",true);
    new Thread(){
     public void run(){
     try{
     sleep(3000);
     }
     catch(Exception e){
     e.printStackTrace();
     }
     finally{
    LayoutInflater regist_Inflater = LayoutInflater.from(Fx.this);
     View fxView = regist_Inflater.inflate(R.layout.activity_fx, null);
     fxView.findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK);//未报错,但是背景没有变黑
     r_Dialog.dismiss();
                                     }
     }
     }.start();
                     }
     }).
     setNegativeButton("取消",null).
     create();//创建登录对话框
    public void onClick(View v){
    registDlg.show();//显示登录对话框
    }
    }
    }
      

  3.   


    你activity没有setContentView()吗,为什么还要重新inflate一个view,直接就findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK)啊
      

  4.   

    R.id.btn_login这个控件直接在setContentView(R.layout.activity_fx);下面做了,然后在你的finally里面不需要在那样得了.直接用
    代码真乱
      

  5.   

     是fxView吗,这个view在fxView.findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK);这一句不是用了吗,完整点的代码是这样的
    public class Fx extends Activity {
    //声明Button对象
    Button button_regist;
    Button button_login;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_fx);        
            /*--------------按钮regist----------------*/
            button_regist = (Button)findViewById(R.id.btn_regist);
            button_regist.setOnClickListener(new btn_registOnclick());      
    }

    /*-------------------------regist监听器--------------------------------*/
    class btn_registOnclick implements OnClickListener{
    ProgressDialog r_Dialog;
    LayoutInflater regist_Inflater = LayoutInflater.from(Fx.this);
    final View registView = regist_Inflater.inflate(R.layout.regist, null);
    AlertDialog registDlg = new AlertDialog.Builder(Fx.this).
                    setTitle("请注册"). 
                    setView(registView).
                    setPositiveButton("确定",  new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton1) {
    // TODO Auto-generated method stub
    r_Dialog = ProgressDialog.show(Fx.this, "请等待...", "正在为您注册...",true);
    new Thread(){
     public void run(){
     try{
     sleep(3000);
     }
     catch(Exception e){
     e.printStackTrace();
     }
     finally{
    LayoutInflater regist_Inflater = LayoutInflater.from(Fx.this);
     View fxView = regist_Inflater.inflate(R.layout.activity_fx, null);
     fxView.findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK);//未报错,但是背景没有变黑
     r_Dialog.dismiss();
                                     }
     }
     }.start();
                     }
     }).
     setNegativeButton("取消",null).
     create();//创建登录对话框
    public void onClick(View v){
    registDlg.show();//显示登录对话框
    }
    }
    }这是layout下的布局文件<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <LinearLayout
        android:id="@+id/info"
        android:layout_centerVertical="true"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">
        <Button
        android:id="@+id/btn_login"
        android:text="@string/fx_login"
        android:textSize="30dp"
        android:layout_width="180dp"
            android:layout_height="100dp"
            android:layout_gravity="left"
            android:visibility="visible"
        >
        </Button>
        <Button
        android:id="@+id/btn_regist"
        android:text="@string/fx_regist"
        android:textSize="30dp"
        android:layout_width="180dp"
            android:layout_height="100dp"
            android:layout_gravity="right"
        >
        </Button>
        </LinearLayout>
    </RelativeLayout>
      

  6.   

    怎么可能会报错,你可能用的不对,你在finally里面用的那个应该是另外new了一个对象出来.但你已经setContentView了.
      

  7.   

    怎么可能会报错,你可能用的不对,你在finally里面用的那个应该是另外new了一个对象出来.但你已经setContentView了.哦,我大概知道我上面的为什么不行了,但是我改回来一执行到这就会这样
      

  8.   

    怎么可能会报错,你可能用的不对,你在finally里面用的那个应该是另外new了一个对象出来.但你已经setContentView了.哦,我大概知道我上面的为什么不行了,但是我改回来一执行到这就会这样R.id.btn_login是这样写进button_login 的
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_fx);
            button_login = (Button)findViewById(R.id.btn_login);
    ...
      

  9.   


    你activity没有setContentView()吗,为什么还要重新inflate一个view,直接就findViewById(R.id.btn_login).setBackgroundColor(Color.BLACK)啊这样改了,帮我再看看,还是不对
      

  10.   

    Fx.this.button_login.setBackgroundColor