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)
加:讲按钮加入布局

上一篇:初次使用百度地图API


下一篇:Extjs4.2纯前台导出Excel总结