setting android button invisible but still having an onClick Listener attached

后端 未结 10 1608
情深已故
情深已故 2021-02-06 06:39

So currently I\'m putting an Easter egg inside my app and I want the Button to be invisible, but when clicked(Rick roll). So far I can make it work when I say:

10条回答
  •  抹茶落季
    2021-02-06 07:13

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         Button b = (Button) findViewById(R.id.button1);
         final CheckBox cb = (CheckBox) findViewById(R.id.checkBox1);
         b.setBackgroundColor(Color.TRANSPARENT);
    
         b.setOnClickListener(new OnClickListener() {
    
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                cb.setChecked(true);
    

    to this code button is invisible but it worked ;))

提交回复
热议问题