在当前视图中动态添加按钮

时间:2013-10-29 14:08:09

标签: java android

我做了一个qrcode阅读器,但我需要添加一个Button ..如何以编程方式添加按钮? 示例:

Button btnVoltar = new Button(this);
    btnVoltar.setText("Voltar");
    btnVoltar.setX(30);
    btnVoltar.setY(30); 

但我需要在视图中添加此按钮。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if(!isCameraAvailable()) {
        // Cancel request if there is no rear-facing camera.
        cancelRequest();
        return;
    }

    // Hide the window title.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    mAutoFocusHandler = new Handler();

    // Create and configure the ImageScanner;
    setupScanner();

    // Create a RelativeLayout container that will hold a SurfaceView,
    // and set it as the content of our activity.

    mPreview = new CameraPreview(this, this, autoFocusCB);
    setContentView(mPreview);
}

0 个答案:

没有答案