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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM