Andy 胡

导航

Android:Java代码添加按钮

        LinearLayout layout = (LinearLayout) findViewById(R.id.container);
        
        Button bn = new Button(this);
        bn.setText("点击");
        bn.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        
        layout.addView(bn);
        
        bn.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View arg0) {
                ComponentName comp = new ComponentName(MainActivity.this, FullscreenActivity02.class);
                Intent intent = new Intent();
                intent.setComponent(comp);
                startActivity(intent);
            }
        });

寻:通过id寻找布局Layout
新:新建按钮
设:设置按钮的文字,式样(new Layout)
加:讲按钮加入布局

posted on 2016-04-24 20:37  talkwah  阅读(5308)  评论(0编辑  收藏  举报