先绑定控件,然后再button的onclick事件里面写,设置控件背景颜色

解决方案 »

  1.   

    写个selector图形资源不行吗?
      

  2.   

    难道是理解错了楼主的意思了,这个没有那么难吧,
    Button but=new Button(this);
    but.setText("按钮");
    but.setBackgroundColor(Color.GRAY);  
    but.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    v.setBackgroundColor(Color.LTGRAY);
    }
    });
      

  3.   

    <?xml version="1.0" encoding="UTF-8"?>
    你在drawable文件夹下定义这样的xml问题,然后这个xml文件当做一张图片设置给button就可以了啊
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:state_pressed="false"
    android:drawable="@drawable/dialog_button_focus" /> <item android:state_focused="true" android:state_pressed="true"
    android:drawable="@drawable/dialog_button_focus" /> <item android:state_focused="false" android:state_pressed="true"
    android:drawable="@drawable/dialog_button_focus" /> <item android:state_focused="false" android:state_pressed="false"
    android:drawable="@drawable/dialog_button_unfocus" /></selector>
      

  4.   

    你在drawable文件夹下定义这样的xml文件,然后这个xml文件当做一张图片设置给button就可以了啊
      

  5.   

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/title_btn_l_color" />
    <item android:drawable="@drawable/chat_title_btn_l" />
    </selector>要这样的?
    还是要
    but_NotPublished.setBackgroundDrawable(label_right_def);
    but_ThePublished.setBackgroundDrawable(label_left_sel);