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
https://github.com/mobapptuts/recyclerview_image_gallery.git Tag camera2-video-record-button
or you can run this command
git clone https://github.com/mobapptuts/recyclerview_image_gallery.git –branch camera2-video-record-button
Steps
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
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_camera2_video_image); mTextureView = (TextureView) findViewById(R.id.textureView); mRecordImageButton = (ImageButton) findViewById(R.id.videoOnlineImageButton); mRecordImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(mIsRecording) { mIsRecording = false; mRecordImageButton.setImageResource(R.mipmap.btn_video_online); } else { mIsRecording = true; mRecordImageButton.setImageResource(R.mipmap.btn_video_busy); } } }); }
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.