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)
加:講按鈕加入布局