android video app enabling record button

The android video app enabling record button tutorial describes the how to create an on click listener for the ImageButton view. And then how to change the image to a red icon for recording and then back to a green icon to indicate that recording is available.

Get Code

The code to start this tutorial is on github here Tag camera2-video-record-button

or you can run this command

git clone –branch camera2-video-record-button


Create a flag to indicate whether the device or recording or not

private boolean mIsRecording = false;

Add an ImageButton member to the activity

private ImageButton mRecordImageButton;

 Inside the onCreate method add the on click listener for the record ImageButton view

    protected void onCreate(Bundle savedInstanceState) {

        mTextureView = (TextureView) findViewById(;
        mRecordImageButton = (ImageButton) findViewById(;
        mRecordImageButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if(mIsRecording) {
                    mIsRecording = false;
                } else {
                    mIsRecording = true;


Android video app enabling record button summary

In the android video app enabling record button tutorial we learned how to change images inside a ImageButton but this same method could be used for any type of view.

The example here showed how to create a toggle button using a boolean flag.

About The Author

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>